21 #include <CUnit/CUnit.h> 22 #include <string_operations.h> 26 #include "libfocunit.h" 29 void test_guess_encoding() {
30 char*
buffer =
"an ascii text";
31 gchar* guessedEncoding = guessEncoding(buffer, strlen(buffer));
34 CU_ASSERT_PTR_NULL(guessedEncoding);
36 CU_ASSERT_PTR_NOT_NULL_FATAL(guessedEncoding);
37 FO_ASSERT_STRING_EQUAL(guessedEncoding,
"us-ascii");
40 if (guessedEncoding) {
41 g_free(guessedEncoding);
45 void test_guess_encodingUtf8() {
46 char* buffer =
"an utf8 ß";
47 gchar* guessedEncoding = guessEncoding(buffer, strlen(buffer));
49 CU_ASSERT_PTR_NOT_NULL_FATAL(guessedEncoding);
52 FO_ASSERT_STRING_EQUAL(guessedEncoding,
"UTF-8");
54 FO_ASSERT_STRING_EQUAL(guessedEncoding,
"utf-8");
57 if (guessedEncoding) {
58 g_free(guessedEncoding);
62 void test_guess_encodingLatin1() {
63 char* buffer =
"a latin1 \xdf\x0a";
64 gchar* guessedEncoding = guessEncoding(buffer, strlen(buffer));
66 CU_ASSERT_PTR_NOT_NULL_FATAL(guessedEncoding);
69 FO_ASSERT_STRING_EQUAL(guessedEncoding,
"windows-1252");
71 FO_ASSERT_STRING_EQUAL(guessedEncoding,
"iso-8859-1");
74 if (guessedEncoding) {
75 g_free(guessedEncoding);
79 CU_TestInfo encoding_testcases[] = {
80 {
"Testing guessing encoding of buffer:", test_guess_encoding},
81 {
"Testing guessing encoding of buffer utf8:", test_guess_encodingUtf8},
82 {
"Testing guessing encoding of buffer Latin1:", test_guess_encodingLatin1},
char buffer[2048]
The last thing received from the scheduler.