[gcalctool] Make unittests pass for conversions
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcalctool] Make unittests pass for conversions
- Date: Thu, 27 Jan 2011 08:12:41 +0000 (UTC)
commit 8a7d2649c256a730ae9f10df6a13a075685f74b0
Author: Robert Ancell <robert ancell canonical com>
Date: Thu Jan 27 18:12:17 2011 +1000
Make unittests pass for conversions
src/unit-category.c | 4 +---
src/unittest.c | 9 +++++++++
2 files changed, 10 insertions(+), 3 deletions(-)
---
diff --git a/src/unit-category.c b/src/unit-category.c
index aae9e98..324e5d1 100644
--- a/src/unit-category.c
+++ b/src/unit-category.c
@@ -88,9 +88,7 @@ unit_category_convert(UnitCategory *category, const MPNumber *x, const char *x_u
unit_x = get_unit(category, x_units);
unit_z = get_unit(category, z_units);
- g_return_val_if_fail(unit_x != NULL, FALSE);
- g_return_val_if_fail(unit_z != NULL, FALSE);
- if (unit_get_value(unit_x) && unit_get_value(unit_z)) {
+ if (unit_x && unit_z && unit_get_value(unit_x) && unit_get_value(unit_z)) {
mp_multiply(x, unit_get_value(unit_x), z);
mp_divide(z, unit_get_value(unit_z), z);
return TRUE;
diff --git a/src/unittest.c b/src/unittest.c
index 4880c2f..059f63d 100644
--- a/src/unittest.c
+++ b/src/unittest.c
@@ -25,6 +25,7 @@
#include "unittest.h"
#include "mp-equation.h"
#include "mp-serializer.h"
+#include "unit-manager.h"
static MPEquationOptions options;
@@ -116,6 +117,13 @@ test(char *expression, char *expected, int expected_error)
}
+static int
+do_convert(const MPNumber *x, const char *x_units, const char *z_units, MPNumber *z, void *data)
+{
+ return unit_manager_convert(unit_manager_get_default(), x, x_units, z_units, z);
+}
+
+
static void
test_conversions()
{
@@ -123,6 +131,7 @@ test_conversions()
options.base = 10;
options.wordlen = 32;
options.angle_units = MP_DEGREES;
+ options.convert = do_convert;
/* Length */
test("1 meter in mm", "1000", 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]