[grisbi-cvs] grisbi/src gsb_real_cunit.c,1.1,1.2

Pierre Biava pbiava at users.sourceforge.net
Tue May 12 06:29:33 CEST 2009


Update of /cvsroot/grisbi/grisbi/src
In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv18463

Modified Files:
	gsb_real_cunit.c 
Log Message:
add test gsb_real_cunit__gsb_real_get_from_string() (HS)

Index: gsb_real_cunit.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_real_cunit.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- gsb_real_cunit.c	11 May 2009 18:54:27 -0000	1.1
+++ gsb_real_cunit.c	12 May 2009 04:29:31 -0000	1.2
@@ -49,8 +49,24 @@
     return 0;
 }
 
+void gsb_real_cunit__gsb_real_get_from_string()
+{
+     //TODO make gsb_real_get_from_string testable without this
+	//~ setlocale ( LC_MONETARY, "C" );
+
+    gsb_real val = gsb_real_get_from_string("123,45");
+    CU_ASSERT_EQUAL(123, val.mantissa);
+    CU_ASSERT_EQUAL(2, val.exponent);
+
+    val = gsb_real_get_from_string("21 000 000");
+    CU_ASSERT_EQUAL(2100000000, val.mantissa);
+    CU_ASSERT_EQUAL(2, val.exponent);
+}
+
 void gsb_real_cunit__gsb_real_raw_format_string()
 {
+    gchar *s;
+    gsb_real n;
     struct lconv conv;
     memset(&conv, 0, sizeof(conv));
     conv.positive_sign = "<+>";
@@ -58,9 +74,22 @@
     conv.mon_thousands_sep = "< >";
     conv.mon_decimal_point = "<.>";
     gchar *currency_symbol = "<¤>";
-    
-    gsb_real n = {31415, 1};
-    gchar *s = gsb_real_raw_format_string(n, &conv, currency_symbol);
+        
+    n.mantissa = 1;
+    n.exponent = 2;
+    s = gsb_real_raw_format_string(n, &conv, currency_symbol);
+    CU_ASSERT_STRING_EQUAL("<+>0<.>01<¤>", s);
+    g_free(s);
+
+    n.mantissa = 10;
+    n.exponent = 2;
+    s = gsb_real_raw_format_string(n, &conv, currency_symbol);
+    CU_ASSERT_STRING_EQUAL("<+>0<.>10<¤>", s);
+    g_free(s);
+
+    n.mantissa = 31415;
+    n.exponent = 1;
+    s = gsb_real_raw_format_string(n, &conv, currency_symbol);
     CU_ASSERT_STRING_EQUAL("<+>3< >141<.>5<¤>", s);
     g_free(s);
 
@@ -162,7 +191,8 @@
     if(NULL == pSuite)
         return NULL;
 
-    if((NULL == CU_add_test(pSuite, "of gsb_real_raw_format_string()", gsb_real_cunit__gsb_real_raw_format_string))
+    if((NULL == CU_add_test(pSuite, "of gsb_real_get_from_string()",   gsb_real_cunit__gsb_real_get_from_string))
+    || (NULL == CU_add_test(pSuite, "of gsb_real_raw_format_string()", gsb_real_cunit__gsb_real_raw_format_string))
     || (NULL == CU_add_test(pSuite, "of gsb_real_add()",               gsb_real_cunit__gsb_real_add))
        )
         return NULL;



More information about the cvs mailing list