[grisbi-cvs] grisbi/src gsb_data_account_cunit.c, 1.3, 1.4 gsb_real_cunit.c, 1.11, 1.12

Mathias Lorente m-lorente at users.sourceforge.net
Tue Mar 9 20:53:30 CET 2010


Update of /cvsroot/grisbi/grisbi/src
In directory sfp-cvsdas-2.v30.ch3.sourceforge.com:/tmp/cvs-serv8393/src

Modified Files:
	gsb_data_account_cunit.c gsb_real_cunit.c 
Log Message:
Update unit test and add localized tests.


Index: gsb_real_cunit.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_real_cunit.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- gsb_real_cunit.c	21 May 2009 21:58:55 -0000	1.11
+++ gsb_real_cunit.c	9 Mar 2010 19:53:28 -0000	1.12
@@ -70,13 +70,66 @@
 
 void gsb_real_cunit__gsb_real_get_from_string ( void )
 {
-    gsb_real val = gsb_real_get_from_string("123,45");
-    CU_ASSERT_EQUAL(12345, val.mantissa);
-    CU_ASSERT_EQUAL(2, val.exponent);
+    char *lc_monetary_orig;
+    char *result = setlocale(LC_MONETARY, NULL);
+    if (result != NULL)
+    {
+        lc_monetary_orig = (char *)malloc((strlen(result) + 1) * sizeof(char));
+        strcpy(lc_monetary_orig, result);
 
-    val = gsb_real_get_from_string("21000000");
-    CU_ASSERT_EQUAL(21000000, val.mantissa);
-    CU_ASSERT_EQUAL(0, val.exponent);
+        /* C test */
+        result = setlocale(LC_MONETARY, "C");
+        if (result != NULL)
+        {
+            gsb_real val = gsb_real_get_from_string("123.45");
+            CU_ASSERT_EQUAL(12345, val.mantissa);
+            CU_ASSERT_EQUAL(2, val.exponent);
+
+            val = gsb_real_get_from_string("21000000");
+            CU_ASSERT_EQUAL(21000000, val.mantissa);
+            CU_ASSERT_EQUAL(0, val.exponent);
+        }
+
+        /* French test */
+        result = setlocale(LC_MONETARY, "fr_FR.UTF-8");
+        if (result == NULL)
+            result = setlocale(LC_MONETARY, "fr_FR at euro");
+        if (result == NULL)
+            result = setlocale(LC_MONETARY, "fr_FR");
+        if (result != NULL)
+        {
+            gsb_real val = gsb_real_get_from_string("123,45");
+            CU_ASSERT_EQUAL(12345, val.mantissa);
+            CU_ASSERT_EQUAL(2, val.exponent);
+
+            val = gsb_real_get_from_string("21000000");
+            CU_ASSERT_EQUAL(21000000, val.mantissa);
+            CU_ASSERT_EQUAL(0, val.exponent);
+        }
+
+        /* English test */
+        result = setlocale(LC_MONETARY, "en_US.UTF-8");
+        if (result == NULL)
+            result = setlocale(LC_MONETARY, "en_GB.UTF-8");
+        if (result == NULL)
+            result = setlocale(LC_MONETARY, "en_US");
+        if (result == NULL)
+            result = setlocale(LC_MONETARY, "en_GB");
+        if (result != NULL)
+        {
+            gsb_real val = gsb_real_get_from_string("123.45");
+            CU_ASSERT_EQUAL(12345, val.mantissa);
+            CU_ASSERT_EQUAL(2, val.exponent);
+
+            val = gsb_real_get_from_string("21 000 000");
+            CU_ASSERT_EQUAL(21000000, val.mantissa);
+            CU_ASSERT_EQUAL(0, val.exponent);
+        }
+
+        /* Restore current locale and free memory */
+        setlocale(LC_MONETARY, lc_monetary_orig);
+        free(lc_monetary_orig) ;
+    }
 }
 
 void gsb_real_cunit__gsb_real_raw_get_from_string()

Index: gsb_data_account_cunit.c
===================================================================
RCS file: /cvsroot/grisbi/grisbi/src/gsb_data_account_cunit.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- gsb_data_account_cunit.c	7 Jun 2009 22:18:31 -0000	1.3
+++ gsb_data_account_cunit.c	9 Mar 2010 19:53:27 -0000	1.4
@@ -66,6 +66,8 @@
 
 void gsb_data_account_cunit__gsb_data_account_calculate_current_and_marked_balances()
 {
+    GDate *date = gdate_today() ;
+
     gint account_number = gsb_data_account_new(GSB_TYPE_BANK);
     CU_ASSERT_EQUAL(1, account_number);
 
@@ -78,6 +80,7 @@
     CU_ASSERT_EQUAL(1, tr_number);
     gsb_real amount = { 2100000021, 2 };
     CU_ASSERT_EQUAL(TRUE, gsb_data_transaction_set_amount(tr_number, amount));
+    CU_ASSERT_EQUAL(TRUE, gsb_data_transaction_set_date(tr_number, date));
     gsb_real balance = gsb_data_account_calculate_current_and_marked_balances(account_number);
     CU_ASSERT_EQUAL(2100000021, balance.mantissa);
     CU_ASSERT_EQUAL(2, balance.exponent);
@@ -86,17 +89,26 @@
     CU_ASSERT_EQUAL(2, tr_number);
     amount.mantissa = 100000000;
     CU_ASSERT_EQUAL(TRUE, gsb_data_transaction_set_amount(tr_number, amount));
+    CU_ASSERT_EQUAL(TRUE, gsb_data_transaction_set_date(tr_number, date));
     balance = gsb_data_account_calculate_current_and_marked_balances(account_number);
+    /* Lose of precision but no overflow */
+    /* Previous test
     CU_ASSERT_EQUAL(0x80000000, balance.mantissa);
     CU_ASSERT_EQUAL(0, balance.exponent);
+    */
+    CU_ASSERT_EQUAL(220000002, balance.mantissa);
+    CU_ASSERT_EQUAL(1, balance.exponent);
     
     tr_number = gsb_data_transaction_new_transaction(account_number);
     CU_ASSERT_EQUAL(3, tr_number);
     amount.mantissa = -100000000;
     CU_ASSERT_EQUAL(TRUE, gsb_data_transaction_set_amount(tr_number, amount));
+    CU_ASSERT_EQUAL(TRUE, gsb_data_transaction_set_date(tr_number, date));
     balance = gsb_data_account_calculate_current_and_marked_balances(account_number);
-    CU_ASSERT_EQUAL(2100000021, balance.mantissa);
-    CU_ASSERT_EQUAL(2, balance.exponent);
+    CU_ASSERT_EQUAL(210000002, balance.mantissa);
+    CU_ASSERT_EQUAL(1, balance.exponent);
+
+    g_date_free(date);
 }
 
 CU_pSuite gsb_data_account_cunit_create_suite()



More information about the cvs mailing list