summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-05-01 09:07:22 +0200
committerDave Davenport <qball@gmpclient.org>2017-05-01 09:07:22 +0200
commitfb11b8ceb6478405afb0f594a2456e9fad1b85fc (patch)
tree1ecd55125e63eadcf89b38da28dfe6f52dc83b48
parentbc428058cbec5c5f5a58e191830e8f6e44418805 (diff)
[Test,Helper] Add test for utf8_strncmp and fuzzy evaluate.
-rw-r--r--include/helper.h2
-rw-r--r--test/helper-test.c27
2 files changed, 28 insertions, 1 deletions
diff --git a/include/helper.h b/include/helper.h
index 246cc737..e3648b6b 100644
--- a/include/helper.h
+++ b/include/helper.h
@@ -244,7 +244,7 @@ int rofi_scorer_fuzzy_evaluate ( const char *pattern, glong plen, const char *st
* are found, respectively, to be less than, to match, or be greater than the first `n`
* characters (not bytes) of `b`.
*/
-int utf8_strncmp ( const char *a, const char* b, size_t n );
+int utf8_strncmp ( const char *a, const char* b, size_t n ) __attribute__((nonnull(1,2)));
/**
* @param wd The work directory (optional)
diff --git a/test/helper-test.c b/test/helper-test.c
index 9f98009f..86d65144 100644
--- a/test/helper-test.c
+++ b/test/helper-test.c
@@ -51,6 +51,14 @@ struct xcb_stuff *xcb;
abort ( ); \
} \
}
+#define TASSERTL( a, b ) { \
+ if ( ( a ) == ( b ) ) { \
+ printf ( "Test %i passed (%s == %s) (%d == %d)\n", ++test, # a, # b, a, b ); \
+ }else { \
+ printf ( "Test %i failed (%s == %s) (%d != %d)\n", ++test, # a, # b, a, b ); \
+ abort ( ); \
+ } \
+}
void rofi_add_error_message ( GString *msg )
{
@@ -145,4 +153,23 @@ int main ( int argc, char ** argv )
TASSERT ( fd >= 0 );
remove_pid_file ( fd );
}
+ {
+ TASSERT ( utf8_strncmp ( "aapno", "aap€",3) == 0 );
+ TASSERT ( utf8_strncmp ( "aapno", "aap€",4) != 0 );
+ TASSERT ( utf8_strncmp ( "aapno", "a",4) != 0 );
+ TASSERT ( utf8_strncmp ( "a", "aap€",4) != 0 );
+// char in[] = "Valid utf8 until \xc3\x28 we continue here";
+// TASSERT ( utf8_strncmp ( in, "Valid", 3 ) == 0);
+ }
+ {
+ TASSERTL ( rofi_scorer_fuzzy_evaluate ("aap noot mies", 12 , "aap noot mies", 12), -605);
+ TASSERTL ( rofi_scorer_fuzzy_evaluate ("anm", 3, "aap noot mies", 12), -155);
+ TASSERTL ( rofi_scorer_fuzzy_evaluate ("blu", 3, "aap noot mies", 12), 1073741824);
+ config.case_sensitive = TRUE;
+ TASSERTL ( rofi_scorer_fuzzy_evaluate ("Anm", 3, "aap noot mies", 12), 1073741754);
+ config.case_sensitive = FALSE;
+ TASSERTL ( rofi_scorer_fuzzy_evaluate ("Anm", 3, "aap noot mies", 12), -155);
+ TASSERTL ( rofi_scorer_fuzzy_evaluate ("aap noot mies", 12,"Anm", 3 ), 1073741824);
+
+ }
}