summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile4
-rw-r--r--locale.c75
-rw-r--r--main.c9
3 files changed, 86 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 9d01eb8..cf84102 100644
--- a/Makefile
+++ b/Makefile
@@ -1,13 +1,15 @@
CC=c89
CFLAGS=-Wall -Wextra -Wpedantic
-testlibc: main.o test.o assert.o ctype.o
+testlibc: main.o test.o assert.o ctype.o locale.o
$(CC) -o $@ *.o
assert.o: assert.c test.h
ctype.o: ctype.c test.h
+locale.o: locale.c test.h
+
test.o: test.c test.h
main.o: main.c test.h
diff --git a/locale.c b/locale.c
new file mode 100644
index 0000000..629ef0b
--- /dev/null
+++ b/locale.c
@@ -0,0 +1,75 @@
+#include <locale.h>
+#include <limits.h>
+#include "test.h"
+
+void test_locale(void)
+{
+ struct lconv *lc;
+
+ testing_header("locale.h");
+
+#ifndef LC_ALL
+#error LC_ALL not defined
+#endif
+
+#ifndef LC_COLLATE
+#error LC_COLLATE not defined
+#endif
+
+#ifndef LC_CTYPE
+#error LC_CTYPE not defined
+#endif
+
+#ifndef LC_MONETARY
+#error LC_MONETARY not defined
+#endif
+
+#ifndef LC_NUMERIC
+#error LC_NUMERIC not defined
+#endif
+
+#ifndef LC_TIME
+#error LC_TIME not defined
+#endif
+
+ test_true(LC_ALL != LC_COLLATE);
+ test_true(LC_ALL != LC_CTYPE);
+ test_true(LC_ALL != LC_MONETARY);
+ test_true(LC_ALL != LC_NUMERIC);
+ test_true(LC_ALL != LC_TIME);
+
+ test_true(LC_COLLATE != LC_CTYPE);
+ test_true(LC_COLLATE != LC_MONETARY);
+ test_true(LC_COLLATE != LC_NUMERIC);
+ test_true(LC_COLLATE != LC_TIME);
+
+ test_true(LC_CTYPE != LC_MONETARY);
+ test_true(LC_CTYPE != LC_NUMERIC);
+ test_true(LC_CTYPE != LC_TIME);
+
+ test_true(LC_MONETARY != LC_NUMERIC);
+ test_true(LC_MONETARY != LC_TIME);
+
+ test_true(LC_NUMERIC != LC_TIME);
+
+ /* TODO: test setlocale() */
+
+ testing_comment("testing results of localeconv()");
+ lc = localeconv();
+ test_string(lc->decimal_point, ".");
+ test_string(lc->thousands_sep, "");
+ test_string(lc->grouping, "");
+ test_string(lc->int_curr_symbol, "");
+ test_string(lc->currency_symbol, "");
+ test_string(lc->mon_decimal_point, "");
+ test_string(lc->mon_thousands_sep, "");
+ test_string(lc->positive_sign, "");
+ test_string(lc->negative_sign, "");
+ test_int_equals(lc->frac_digits, CHAR_MAX);
+ test_int_equals(lc->p_cs_precedes, CHAR_MAX);
+ test_int_equals(lc->p_sep_by_space, CHAR_MAX);
+ test_int_equals(lc->n_cs_precedes, CHAR_MAX);
+ test_int_equals(lc->n_sep_by_space, CHAR_MAX);
+ test_int_equals(lc->p_sign_posn, CHAR_MAX);
+ test_int_equals(lc->n_sign_posn, CHAR_MAX);
+}
diff --git a/main.c b/main.c
index 09c2d4a..be6fc76 100644
--- a/main.c
+++ b/main.c
@@ -1,8 +1,15 @@
+#include <string.h>
#include "test.h"
int main(int argc, char *argv[])
{
+ if (argc == 2) {
+ if (!strcmp(argv[1], "assert")) {
+ test_assert();
+ }
+ }
+
test_ctype();
- test_assert();
+ test_locale();
return 0;
}