Browse Source

str: test for faux_str_getline()

Serj Kalichev 2 years ago
parent
commit
0a2c07c936
2 changed files with 39 additions and 0 deletions
  1. 38 0
      faux/str/testc_str.c
  2. 1 0
      faux/testc_module/testc_module.c

+ 38 - 0
faux/str/testc_str.c

@@ -55,3 +55,41 @@ int testc_faux_str_nextword(void)
 
 	return retval;
 }
+
+
+int testc_faux_str_getline(void)
+{
+	const char* line = "arg 0\narg 1\narg 2";
+	const char* etalon[] = {
+		"arg 0",
+		"arg 1",
+		"arg 2",
+		NULL
+		 };
+	ssize_t num_etalon = 3;
+	size_t index = 0;
+	char *str = NULL;
+	const char *saveptr = NULL;
+
+	printf("Line   : [%s]\n", line);
+
+	saveptr = line;
+	while ((str = faux_str_getline(saveptr, &saveptr)) && (index < num_etalon)) {
+		int r = -1;
+		const char *res = NULL;
+		printf("Etalon %ld : [%s]\n", index, etalon[index]);
+		r = strcmp(etalon[index], str);
+		if (r < 0) {
+			printf("Not equal %ld [%s]\n", index, str);
+			return -1;
+		}
+		faux_str_free(str);
+		index++;
+	}
+	if (index != num_etalon) {
+		printf("Number of args is not equal real=%ld etalon=%ld\n", index, num_etalon);
+		return -1;
+	}
+
+	return 0;
+}

+ 1 - 0
faux/testc_module/testc_module.c

@@ -15,6 +15,7 @@ const char *testc_module[][2] = {
 
 	// str
 	{"testc_faux_str_nextword", "Find next word (quotation)"},
+	{"testc_faux_str_getline", "Get line from string"},
 
 	// ini
 	{"testc_faux_ini_parse_file", "Complex test of INI file parsing"},