Pārlūkot izejas kodu

tests: Tests for faux_str_casecmpn().

Serj Kalichev 4 mēneši atpakaļ
vecāks
revīzija
e66d8763fc
2 mainītis faili ar 36 papildinājumiem un 0 dzēšanām
  1. 35 0
      faux/str/testc_str.c
  2. 1 0
      faux/testc_module/testc_module.c

+ 35 - 0
faux/str/testc_str.c

@@ -156,3 +156,38 @@ int testc_faux_str_c_esc_quote(void)
 
 	return 0;
 }
+
+
+int testc_faux_str_casecmpn(void)
+{
+	const char *line_long = "abcdefj";
+	const char *line_short = "abcde";
+	const char *line_diff = "abche";
+
+	if (faux_str_casecmpn(line_long, line_short, strlen(line_short)) != 0) {
+		printf("Equal string comparison problem\n");
+		return -1;
+	}
+
+	if (faux_str_casecmpn(line_long, line_short, strlen(line_long)) <= 0) {
+		printf("Sort string comparison problem\n");
+		return -1;
+	}
+
+	if (faux_str_casecmpn(line_long, line_diff, strlen(line_diff)) >= 0) {
+		printf("Different string comparison problem\n");
+		return -1;
+	}
+
+	if (faux_str_casecmpn(line_long, NULL, strlen(line_long)) <= 0) {
+		printf("Broken first string comparison with NULL\n");
+		return -1;
+	}
+
+	if (faux_str_casecmpn(NULL, line_long, strlen(line_long)) >= 0) {
+		printf("Broken second string comparison with NULL\n");
+		return -1;
+	}
+
+	return 0;
+}

+ 1 - 0
faux/testc_module/testc_module.c

@@ -18,6 +18,7 @@ const char *testc_module[][2] = {
 	{"testc_faux_str_getline", "Get line from string"},
 	{"testc_faux_str_numcmp", "Numeric comparison"},
 	{"testc_faux_str_c_esc_quote", "Escape and add quotes for string with spaces"},
+	{"testc_faux_str_casecmpn", "String comparison with length"},
 
 	// ini
 	{"testc_faux_ini_parse_file", "Complex test of INI file parsing"},