[recipes] Fix some test build issues
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Fix some test build issues
- Date: Mon, 26 Dec 2016 14:06:13 +0000 (UTC)
commit 219c71cab65d97c43d0a344e15ad7210599ac7ce
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 26 08:28:22 2016 -0500
Fix some test build issues
The way we currently build the tests is not ideal, we simply
include all the required sources. This can lead to conflicts
between identically named static functions, so move all the
common helper functions to the gr-utils.c source file and
include that as well.
src/gr-ingredients-list.c | 8 +-------
src/gr-number.c | 22 +++-------------------
src/gr-unit.c | 11 +++--------
src/gr-utils.c | 17 +++++++++++++++++
src/gr-utils.h | 4 ++++
tests/ingredients.c | 10 +++++++---
tests/number.c | 3 +++
tests/unit.c | 2 ++
8 files changed, 40 insertions(+), 37 deletions(-)
---
diff --git a/src/gr-ingredients-list.c b/src/gr-ingredients-list.c
index b7ede6a..fbc2829 100644
--- a/src/gr-ingredients-list.c
+++ b/src/gr-ingredients-list.c
@@ -27,6 +27,7 @@
#include "gr-ingredient.h"
#include "gr-number.h"
#include "gr-unit.h"
+#include "gr-utils.h"
/* Parsing ingredients is tricky business. We operate under the following
@@ -64,13 +65,6 @@ struct _GrIngredientsList
G_DEFINE_TYPE (GrIngredientsList, gr_ingredients_list, G_TYPE_OBJECT)
-static void
-skip_whitespace (char **line)
-{
- while (g_ascii_isspace (**line))
- (*line)++;
-}
-
static gboolean
gr_ingredients_list_add_one (GrIngredientsList *ingredients,
char *line,
diff --git a/src/gr-number.c b/src/gr-number.c
index e7160cb..eb89665 100644
--- a/src/gr-number.c
+++ b/src/gr-number.c
@@ -20,7 +20,9 @@
#include <glib/gi18n.h>
#include <gio/gio.h>
-#include <gr-number.h>
+
+#include "gr-number.h"
+#include "gr-utils.h"
static int
gcd (int m, int n)
@@ -138,12 +140,6 @@ static NumberForm numberforms[] = {
};
static gboolean
-space_or_nul (char p)
-{
- return (p == '\0' || g_ascii_isspace (p));
-}
-
-static gboolean
parse_as_number_form (GrNumber *number,
char **input,
GError **error)
@@ -275,18 +271,6 @@ parse_as_integer (GrNumber *number,
}
static gboolean
-skip_whitespace (char **input)
-{
- char **in = input;
-
- while (*input && g_ascii_isspace (**input)) {
- *input += 1;
- }
-
- return *in != *input;
-}
-
-static gboolean
parse_as_float (GrNumber *number,
char **input,
GError **error)
diff --git a/src/gr-unit.c b/src/gr-unit.c
index cb36940..435d623 100644
--- a/src/gr-unit.c
+++ b/src/gr-unit.c
@@ -22,8 +22,9 @@
#include <gio/gio.h>
#include "gr-unit.h"
+#include "gr-utils.h"
-static const char * const names[] = {
+static const char * const unit_names[] = {
"g", "kg", "lb", "oz", "l", "dl", "ml", "fl oz", "pt", "qt", "gal", "cup",
"tbsp", "tsp", "box", "pkg",
NULL
@@ -58,7 +59,7 @@ static GrUnit units[] = {
const char **
gr_unit_get_names (void)
{
- return (const char **)names;
+ return (const char **)unit_names;
}
static GrUnit *
@@ -99,12 +100,6 @@ gr_unit_get_abbreviation (const char *name)
return NULL;
}
-static gboolean
-space_or_nul (char p)
-{
- return (p == '\0' || g_ascii_isspace (p));
-}
-
const char *
gr_unit_parse (char **input,
GError **error)
diff --git a/src/gr-utils.c b/src/gr-utils.c
index 603d6cd..5ce9d95 100644
--- a/src/gr-utils.c
+++ b/src/gr-utils.c
@@ -287,3 +287,20 @@ date_time_from_string (const char *string)
return NULL;
}
+gboolean
+skip_whitespace (char **input)
+{
+ char *in = *input;
+
+ while (*input && g_ascii_isspace (**input)) {
+ *input += 1;
+ }
+
+ return in != *input;
+}
+
+gboolean
+space_or_nul (char p)
+{
+ return (p == '\0' || g_ascii_isspace (p));
+}
diff --git a/src/gr-utils.h b/src/gr-utils.h
index 696f2f8..3b0ad13 100644
--- a/src/gr-utils.h
+++ b/src/gr-utils.h
@@ -45,4 +45,8 @@ void gr_utils_widget_set_css_simple (GtkWidget *widget,
char * date_time_to_string (GDateTime *dt);
GDateTime * date_time_from_string (const char *string);
+gboolean skip_whitespace (char **input);
+gboolean space_or_nul (char p);
+
+
G_END_DECLS
diff --git a/tests/ingredients.c b/tests/ingredients.c
index 802f9c6..b7f7080 100644
--- a/tests/ingredients.c
+++ b/tests/ingredients.c
@@ -23,6 +23,10 @@
#include "gr-ingredients-list.c"
#include "gr-ingredient.h"
#include "gr-ingredient.c"
+#include "gr-number.h"
+#include "gr-number.c"
+#include "gr-unit.h"
+#include "gr-unit.c"
#include "gr-utils.h"
#include "gr-utils.c"
@@ -50,10 +54,10 @@ test_file (const char *filename)
ingredients = gr_ingredients_list_new (contents);
for (l = ingredients->ingredients; l; l = l->next) {
Ingredient *ing = (Ingredient *)l->data;
- if (ing->fraction)
- g_string_append_printf (string, "AMOUNT %d/%d\n", ing->num, ing->denom);
+ if (ing->amount.fraction)
+ g_string_append_printf (string, "AMOUNT %d/%d\n", ing->amount.num,
ing->amount.denom);
else
- g_string_append_printf (string, "AMOUNT %f\n", ing->value);
+ g_string_append_printf (string, "AMOUNT %f\n", ing->amount.value);
g_string_append_printf (string, "UNIT %s\n", ing->unit);
g_string_append_printf (string, "NAME %s\n", ing->name);
g_string_append_printf (string, "\n");
diff --git a/tests/number.c b/tests/number.c
index c9775cc..0dae5ef 100644
--- a/tests/number.c
+++ b/tests/number.c
@@ -19,9 +19,12 @@
#include "config.h"
#include <locale.h>
#include <stdio.h>
+#include <string.h>
#include <glib.h>
#include "gr-number.h"
#include "gr-number.c"
+#include "gr-utils.h"
+#include "gr-utils.c"
static GString *string;
diff --git a/tests/unit.c b/tests/unit.c
index 1651ce3..13c675f 100644
--- a/tests/unit.c
+++ b/tests/unit.c
@@ -22,6 +22,8 @@
#include <glib.h>
#include "gr-unit.h"
#include "gr-unit.c"
+#include "gr-utils.h"
+#include "gr-utils.c"
static GString *string;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]