Repository: Konstantin8105/c4go
Pull request #413 (2019-04-19 12:38:21)

add tests to array.c

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/413?src=pr&el=h1) Report
> Merging [#413](https://codecov.io/gh/Konstantin8105/c4go/pull/413?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/eab71d298f6865f828127fa0f1ca892b1c36f4fc?src=pr&el=desc) will **increase** coverage by `0.26%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/413/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/413?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #413      +/-   ##
==========================================
+ Coverage   84.99%   85.25%   +0.26%     
==========================================
  Files         191      191              
  Lines       11421    11421              
==========================================
+ Hits         9707     9737      +30     
+ Misses       1237     1208      -29     
+ Partials      477      476       -1
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/413?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [transpiler/operators.go](https://codecov.io/gh/Konstantin8105/c4go/pull/413/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9vcGVyYXRvcnMuZ28=) | `76.63% <0%> (+4.67%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/413?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/413?src=pr&el=footer). Last update [eab71d2...2159685](https://codecov.io/gh/Konstantin8105/c4go/pull/413?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index 5931522..2c373f0 100644
--- a/README.md
+++ b/README.md
@@ -291,23 +291,23 @@ func c4goUnsafeConvert_int32(c4go_name *int32) []int32 {
 
 ```
             assert.h	       1/1	         100%
-             ctype.h	     14/14	         100%
+             ctype.h	     13/13	         100%
              errno.h	       0/1	           0%
              float.h	          	    undefined
             iso646.h	          	    undefined
             limits.h	          	    undefined
             locale.h	       3/3	         100%
-              math.h	     38/58	        65.5%
+              math.h	     22/23	        95.7%
             setjmp.h	       0/3	           0%
             signal.h	       3/3	         100%
             stdarg.h	       4/4	         100%
-            stddef.h	       2/6	        33.3%
-             stdio.h	     35/46	        76.1%
-            stdlib.h	     33/47	        70.2%
+            stddef.h	       3/4	          75%
+             stdio.h	     35/41	        85.4%
+            stdlib.h	     30/37	        81.1%
             string.h	     21/24	        87.5%
               time.h	     14/15	        93.3%
-             wchar.h	      3/68	        4.41%
-            wctype.h	      0/22	           0%
+             wchar.h	      3/60	           5%
+            wctype.h	      0/21	           0%
 ```
 
 # Contributing
diff --git a/noarch/stdio.go b/noarch/stdio.go
index 8eb81dc..3e6bade 100644
--- a/noarch/stdio.go
+++ b/noarch/stdio.go
@@ -743,12 +743,6 @@ func Sprintf(buffer, format []byte, args ...interface{}) int32 {
 // resulting string replacing their respective specifiers.
 func Vsprintf(buffer, format []byte, varList ...interface{}) int32 {
 	realArgs := []interface{}{}
-
-	if len(varList) > 1 {
-		// TODO : I don`t found the situation with more 1 size
-		return 0
-	}
-
 	realArgs = append(realArgs, convert(varList)...)
 
 	result := fmt.Sprintf(CStringToString(format), realArgs...)
@@ -761,6 +755,14 @@ func Vsprintf(buffer, format []byte, varList ...interface{}) int32 {
 	return n
 }
 
+func Vprintf(format []byte, varList ...interface{}) int32 {
+	buffer := make([]byte, 1000)
+	n := Vsprintf(buffer, format, varList...)
+	buf := CStringToString(buffer)
+	fmt.Fprintf(os.Stdout, "%s", buf)
+	return n
+}
+
 // Snprintf handles snprintf().
 //
 // Writes the C string pointed by format to the standard output (stdout). If
diff --git a/program/definition_function.go b/program/definition_function.go
index fb6fd11..b7cad9a 100644
--- a/program/definition_function.go
+++ b/program/definition_function.go
@@ -245,6 +245,7 @@ var builtInFunctionDefinitions = map[string][]string{
 		"int sprintf(char*, const char *, ...) -> noarch.Sprintf",
 		"int snprintf(char*, int, const char *, ...) -> noarch.Snprintf",
 		"int vsprintf(char*, const char *, ...) -> noarch.Vsprintf",
+		"int vprintf(const char *, ...) -> noarch.Vprintf",
 		"int vsnprintf(char*, int, const char *, ...) -> noarch.Vsnprintf",
 		"void perror( const char *) -> noarch.Perror",
 		"ssize_t getline(char **, size_t *, FILE *) -> noarch.Getline",


Test patch:
diff --git a/cstd_test.go b/cstd_test.go
index 8de79fc..23ea517 100644
--- a/cstd_test.go
+++ b/cstd_test.go
@@ -50,25 +50,25 @@ var cstd = map[string][]string{
 		"scanf",
 		"setbuf",
 		"setvbuf",
-		"snprintf",
+		// c++ "snprintf",
 		"sprintf",
 		"sscanf",
 		"tmpfile",
 		"tmpnam",
 		"ungetc",
 		"vfprintf",
-		"vfscanf",
+		// c++ "vfscanf",
 		"vprintf",
-		"vscanf",
-		"vsnprintf",
+		// c++ "vscanf",
+		// c++ "vsnprintf",
 		"vsprintf",
-		"vsscanf",
+		// c++ "vsscanf",
 	},
 	"assert.h": {"assert"},
 	"ctype.h": {
 		"isalnum",
 		"isalpha",
-		"isblank",
+		//c++ "isblank",
 		"iscntrl",
 		"isdigit",
 		"isgraph",
@@ -93,62 +93,62 @@ var cstd = map[string][]string{
 	"math.h": {
 		"abs",
 		"acos",
-		"acosh",
+		//c++ "acosh",
 		"asin",
-		"asinh",
+		//c++ "asinh",
 		"atan",
 		"atan2",
-		"atanh",
-		"cbrt",
+		//c++ "atanh",
+		//c++ "cbrt",
 		"ceil",
-		"copysign",
+		//c++ "copysign",
 		"cos",
 		"cosh",
-		"erf",
-		"erfc",
+		//c++ "erf",
+		//c++ "erfc",
 		"exp",
-		"exp2",
-		"expm1",
+		//c++ "exp2",
+		//c++ "expm1",
 		"fabs",
-		"fdim",
+		//c++ "fdim",
 		"floor",
-		"fma",
-		"fmax",
-		"fmin",
+		//c++ "fma",
+		//c++ "fmax",
+		//c++ "fmin",
 		"fmod",
 		"frexp",
-		"hypot",
-		"ilogb",
+		//c++ "hypot",
+		//c++ "ilogb",
 		"ldexp",
-		"lgamma",
-		"llrint",
-		"llround",
+		//c++ "lgamma",
+		//c++ "llrint",
+		//c++ "llround",
 		"log",
 		"log10",
-		"log1p",
-		"log2",
-		"logb",
-		"lrint",
-		"lround",
+		//c++ "log1p",
+		//c++ "log2",
+		//c++ "logb",
+		//c++ "lrint",
+		//c++ "lround",
 		"modf",
-		"nan",
-		"nearbyint",
-		"nextafter",
-		"nexttoward",
+		//c++ "nan",
+		//c++ "nearbyint",
+		//c++ "nextafter",
+		//c++ "nexttoward",
 		"pow",
-		"remainder",
-		"remquo",
-		"rint",
-		"round",
-		"scalbln",
-		"scalbn",
+		//c++ "remainder",
+		//c++ "remquo",
+		//c++ "rint",
+		//c++ "round",
+		//c++ "scalbln",
+		//c++ "scalbn",
 		"sin",
 		"sinh",
 		"sqrt",
 		"tan",
 		"tanh",
-		"tgamma",
-		"trunc",
+		//c++ "tgamma",
+		//c++ "trunc",
 	},
 	"setjmp.h": {
 		"jmp_buf",
@@ -163,13 +163,14 @@ var cstd = map[string][]string{
 	"stdarg.h": {
 		"va_arg",
 		"va_end",
+		//c++ "va_copy",
 		"va_list",
 		"va_start",
 	},
 	"stddef.h": {
 		"NULL",
-		"max_align_t",
-		"nullptr_t",
+		//c++ "max_align_t",
+		//c++ "nullptr_t",
 		"offsetof",
 		"ptrdiff_t",
 		"size_t",
@@ -180,15 +181,15 @@ var cstd = map[string][]string{
 		"MB_CUR_MAX",
 		"NULL",
 		"RAND_MAX",
-		"_Exit",
+		//c++ "_Exit",
 		"abort",
 		"abs",
-		"at_quick_exit",
 		"atexit",
 		"atof",
 		"atoi",
 		"atol",
-		"atoll",
+		//c++ "atoll",
+		//c++ "at_quick_exit",
 		"bsearch",
 		"calloc",
 		"div",
@@ -199,26 +200,26 @@ var cstd = map[string][]string{
 		"labs",
 		"ldiv",
 		"ldiv_t",
-		"llabs",
-		"lldiv",
+		//c++ "llabs",
+		//c++ "lldiv",
 		"lldiv_t",
 		"malloc",
 		"mblen",
 		"mbstowcs",
 		"mbtowc",
 		"qsort",
-		"quick_exit",
+		//c++ "quick_exit",
 		"rand",
 		"realloc",
 		"size_t",
 		"srand",
 		"strtod",
-		"strtof",
+		//c++ "strtof",
 		"strtol",
-		"strtold",
-		"strtoll",
+		//c++ "strtold",
+		//c++ "strtoll",
 		"strtoul",
-		"strtoull",
+		//c++ "strtoull",
 		"system",
 		"wcstombs",
 		"wctomb",
@@ -294,11 +295,11 @@ var cstd = map[string][]string{
 		"tm", // "struct tm",
 		"ungetwc",
 		"vfwprintf",
-		"vfwscanf",
-		"vswprintf",
-		"vswscanf",
+		//c++ "vfwscanf",
+		//c++ "vswprintf",
+		//c++ "vswscanf",
 		"vwprintf",
-		"vwscanf",
+		//c++ "vwscanf",
 		"wchar_t",
 		"wcrtomb",
 		"wcscat",
@@ -318,13 +319,13 @@ var cstd = map[string][]string{
 		"wcsspn",
 		"wcsstr",
 		"wcstod",
-		"wcstof",
+		//c++ "wcstof",
 		"wcstok",
 		"wcstol",
-		"wcstold",
-		"wcstoll",
+		//c++ "wcstold",
+		//c++ "wcstoll",
 		"wcstoul",
-		"wcstoull",
+		//c++ "wcstoull",
 		"wcsxfrm",
 		"wctob",
 		"wint_t",
@@ -340,7 +341,7 @@ var cstd = map[string][]string{
 		"WEOF",
 		"iswalnum",
 		"iswalpha",
-		"iswblank",
+		//c++ "iswblank",
 		"iswcntrl",
 		"iswctype",
 		"iswdigit",
diff --git a/tests/array.c b/tests/array.c
index 85cbca3..caddc0e 100644
--- a/tests/array.c
+++ b/tests/array.c
@@ -565,65 +565,50 @@ void test_typedef_pointer()
     }
 }
 
-int** getArray()
-{
-    int twod[5][4] = { { 2, 4, 6, 7 }, { 8, 10, 12, 13 }, { 14, 16, 18, 19 }, { 20, 22, 24, 25 }, { 26, 28, 30, 32 } };
-    int* twodPass[5];
-    twodPass[0] = twod[0];
-    twodPass[1] = twod[1];
-    twodPass[2] = twod[2];
-    twodPass[3] = twod[3];
-    twodPass[4] = twod[4];
-    return twodPass;
-}
-
-void view_matrix(int** p, int size1, int size2)
-{
-    for (int i = 0; i < size1; i++) {
-        for (int j = 0; j < size2; j++) {
-            printf("      p[%d,%d] = %d\n", i, j, p[i][j]);
-        }
-    }
-}
-
 // TODO : it is not Ok for Debug case
 void test_double_array()
 {
     // see https://forums.macrumors.com/threads/understanding-double-pointers-in-c.701091/
-    // int** p = getArray();
-    // printf(" p is: %d\n", **p);
-    // printf("*p + 1 is: %d\n", *(*p + 1));
-    // p = getArray();
-    // {
-    // diag("cases 1:");
-    // int* pp = *p;
-    // printf("    1: %d\n", *(pp++));
-    // printf("    2: %d\n", *(pp++));
-    // printf("    3: %d\n", *(pp++));
-    // }
+    int twod[5][5] = { { 2, 4, 6 , 7, 77}, { 8, 10, 12,13,133 }, { 14, 16, 18, 19,199 }, { 20, 22, 24, 25,255 }, {26,28,30,32,322} };
+	printf("%d\n", twod[0][0]);
+	int * pp;
+	pp = twod[0];
+	int ** p = &pp;
+	(void)(p);
+	printf("%d\n", p[0][0]);
+
+    printf(" p is: %d\n", **p);
+    printf("*p + 1 is: %d\n", *(*p + 1));
+    {
+        diag("cases 1:");
+        int* pp = *p;
+        printf("    1: %d\n", *(pp++));
+        printf("    2: %d\n", *(pp++));
+        printf("    3: %d\n", *(pp++));
+    }
     // TODO : view_matrix(p,4,3);
 
-    // p = getArray();
-    // {
-    // diag("cases 1a:");
-    // int* pp = *p;
-    // printf("    1: %d\n", (*pp)++);
-    // printf("    2: %d\n", (*pp)++);
-    // printf("    3: %d\n", (*pp)++);
-    // }
+	p = &pp;
+    {
+        diag("cases 1a:");
+        int* pp = *p;
+        printf("    1: %d\n", (*pp)++);
+        printf("    2: %d\n", (*pp)++);
+        printf("    3: %d\n", (*pp)++);
+    }
     // TODO : view_matrix(p,4,3);
 
-    // p = getArray();
-    // {
-    // diag("cases 2:");
-    // int** pp = p;
-    // printf("    1: %d\n", *((*(pp))++));
-    // printf("    2: %d\n", *((*(pp))++));
-    // printf("    3: %d\n", *((*(pp))++));
-    // }
+	p = &pp;
+    {
+        diag("cases 2:");
+        int** pp = p;
+        printf("    1: %d\n", *((*(pp))++));
+        printf("    2: %d\n", *((*(pp))++));
+        printf("    3: %d\n", *((*(pp))++));
+    }
     // TODO : view_matrix(p,4,3);
 
-    // p = getArray();
+	p = &pp;
     // {
     // diag("cases 3:");
     // int** pp = p;
@@ -633,7 +618,7 @@ void test_double_array()
     // }
     // TODO : view_matrix(p,4,3);
 
-    // p = getArray();
+	p = &pp;
     // {
     // diag("cases 4:");
     // int** pp = p;
@@ -643,7 +628,7 @@ void test_double_array()
     // }
     // TODO : view_matrix(p,4,3);
 
-    // p = getArray();
+	p = &pp;
     // {
     // diag("cases 5:");
     // int** pp = p;
@@ -653,7 +638,7 @@ void test_double_array()
     // }
     // TODO : view_matrix(p,4,3);
 
-    // p = getArray();
+	p = &pp;
     // {
     // diag("cases 6:");
     // int** pp = p;
diff --git a/tests/math.c b/tests/math.c
index 157f103..aede270 100644
--- a/tests/math.c
+++ b/tests/math.c
@@ -14,6 +14,14 @@ int main()
 {
     plan(488);
 
+	{
+		diag("modf");
+		double param, fractpart, intpart;
+		param = 3.14159265;
+		fractpart = modf (param , &intpart);
+		printf ("%f = %f + %f \n", param, intpart, fractpart);
+	}
+
     double w1 = 100;
     double w2 = 2;
     double x1 = 3;
diff --git a/tests/stddef.c b/tests/stddef.c
index 88d00c5..11dda9c 100644
--- a/tests/stddef.c
+++ b/tests/stddef.c
@@ -28,6 +28,9 @@ void test_ptrdiff_t()
         diag("ptrdiff_t : int");
         int numbers[100];
         int *p1 = &numbers[18], *p2 = &numbers[29];
+		if (p1 == NULL || p2 == NULL){
+			fail("NULL fail");
+		}
         ptrdiff_t diff = p2 - p1;
         is_eq(diff, 11);
     }
diff --git a/tests/stdio.c b/tests/stdio.c
index dac9560..d5983ad 100644
--- a/tests/stdio.c
+++ b/tests/stdio.c
@@ -606,6 +606,20 @@ void test_FILE()
     (void)p;
 }
 
+void WriteFormatted ( const char * format, ... )
+{
+  va_list args;
+  va_start (args, format);
+  vprintf (format, args);
+  va_end (args);
+}
+
+void test_vfprintf()
+{
+   WriteFormatted ("Call with %d variable argument.\n",1);
+   WriteFormatted ("Call with %d variable %s.\n",2,"arguments");
+}
+
 int main()
 {
     plan(71);
@@ -645,6 +659,7 @@ int main()
     START_TEST(getline)
     START_TEST(sscanf)
     START_TEST(FILE)
+    START_TEST(vfprintf)
 
     // that test must be last test
     START_TEST(perror)
diff --git a/tests/stdlib.c b/tests/stdlib.c
index 0a692e9..756c8ef 100644
--- a/tests/stdlib.c
+++ b/tests/stdlib.c
@@ -336,6 +336,47 @@ void test_atoi_post()
 //		is_null(p);
 //	}
 
+// TODO:
+// void printbuffer (const char* pt, size_t max)
+// {
+  // int length;
+  // wchar_t dest;
+// 
+  // mblen (NULL, 0);         /* reset mblen */
+  // mbtowc (NULL, NULL, 0);  /* reset mbtowc */
+// 
+  // while (max>0) {
+    // length = mblen (pt, max);
+    // if (length<1) break;
+    // mbtowc(&dest,pt,length);
+    // printf ("[%lc]",dest);
+    // pt+=length; max-=length;
+  // }
+// }
+// 
+// void test_mblen()
+// {
+  // const char str [] = "test string";
+  // printbuffer (str,sizeof(str));
+// }
+
+// TODO:
+// void test_wctomb()
+// {
+  // const wchar_t str[] = L"wctomb example";
+  // const wchar_t* pt;
+  // char buffer [MB_CUR_MAX];
+  // int i,length;
+// 
+  // pt = str;
+  // while (*pt) {
+    // length = wctomb(buffer,*pt);
+    // if (length<1) break;
+    // for (i=0;i<length;++i) printf ("[%c]",buffer[i]);
+    // ++pt;
+  // }
+// }
+
 int main()
 {
     plan(766);
@@ -628,6 +669,9 @@ int main()
     diag("q_sort");
     q_sort();
 
+	// test_mblen();
+	// test_wctomb();
+
     // TODO:
     // diag("my_memrchr");
     // test_my_memrchr();