seed r688 - trunk/tests/c



Author: hortont
Date: Fri Jan  9 02:04:22 2009
New Revision: 688
URL: http://svn.gnome.org/viewvc/seed?rev=688&view=rev

Log:
Quick closure tests.


Added:
   trunk/tests/c/api-closure.c
Modified:
   trunk/tests/c/Makefile.am
   trunk/tests/c/api-types.c
   trunk/tests/c/main.c
   trunk/tests/c/test-common.h

Modified: trunk/tests/c/Makefile.am
==============================================================================
--- trunk/tests/c/Makefile.am	(original)
+++ trunk/tests/c/Makefile.am	Fri Jan  9 02:04:22 2009
@@ -3,7 +3,8 @@
 test_SOURCES =					\
 	main.c						\
 	basic.c						\
-	api-types.c
+	api-types.c					\
+	api-closure.c
 	
 test_CFLAGS = -Wall				\
 	 $(SEED_CFLAGS)

Added: trunk/tests/c/api-closure.c
==============================================================================
--- (empty file)
+++ trunk/tests/c/api-closure.c	Fri Jan  9 02:04:22 2009
@@ -0,0 +1,46 @@
+#include "../../libseed/seed.h"
+#include "test-common.h"
+
+SeedValue do_some_math(SeedContext ctx,
+					   SeedObject function,
+					   SeedObject this_object,
+					   size_t argument_count,
+					   const SeedValue arguments[],
+					   SeedException * exception)
+{
+	g_assert(argument_count == 4);
+	
+	guint a = seed_value_to_uint(ctx, arguments[0], NULL);
+	gdouble b = seed_value_to_int(ctx, arguments[1], NULL);
+	gint c = seed_value_to_int(ctx, arguments[2], NULL);
+	gchar * d = seed_value_to_string(ctx, arguments[3], NULL);
+	
+	g_assert(d[0] == 'a');
+	
+	return seed_value_from_double(ctx, (a+b)/c, NULL);
+}
+
+void closures(TestSimpleFixture * fixture, gconstpointer _data)
+{
+	TestSharedState * state = (TestSharedState *)_data;
+	
+	seed_create_function(state->eng->context, "do_some_math",
+						 (SeedFunctionCallback)do_some_math,
+						 (SeedObject)state->eng->global);
+	
+	SeedValue * val = seed_simple_evaluate(state->eng->context,
+										   "do_some_math(5, 8.66, -2, 'a')");
+	g_assert(seed_value_to_double(state->eng->context, val, NULL) == -6.5);
+	
+	SeedObject * dsm_obj = seed_object_get_property(state->eng->context,
+													(SeedObject) state->eng->global,
+													"do_some_math");
+	SeedValue args[4];
+	args[0] = seed_value_from_uint(state->eng->context, 5, NULL);
+	args[1] = seed_value_from_double(state->eng->context, 8.66, NULL);
+	args[2] = seed_value_from_int(state->eng->context, -2, NULL);
+	args[3] = seed_value_from_string(state->eng->context, "a", NULL);
+	val = seed_object_call(state->eng->context, dsm_obj, NULL, 4, args, NULL);
+	
+	g_assert(seed_value_to_double(state->eng->context, val, NULL) == -6.5);
+}

Modified: trunk/tests/c/api-types.c
==============================================================================
--- trunk/tests/c/api-types.c	(original)
+++ trunk/tests/c/api-types.c	Fri Jan  9 02:04:22 2009
@@ -3,14 +3,12 @@
 
 void basic_types(TestSimpleFixture * fixture, gconstpointer _data)
 {
-	TestSharedState * state = (TestSharedState *)_data;
-	
 	// bool to/from JS equality
 	
 	gboolean bool_test_in = TRUE;
-	SeedValue * bool_test = seed_value_from_boolean(state->eng->context,
+	SeedValue * bool_test = seed_value_from_boolean(fixture->context,
 													bool_test_in, NULL);
-	gboolean bool_test_out = seed_value_to_boolean(state->eng->context,
+	gboolean bool_test_out = seed_value_to_boolean(fixture->context,
 												   bool_test, NULL);
 	
 	g_assert(bool_test_in == bool_test_out);
@@ -18,9 +16,9 @@
 	// uint to/from JS equality
 	
 	guint uint_test_in = 2946623;
-	SeedValue * uint_test = seed_value_from_uint(state->eng->context,
+	SeedValue * uint_test = seed_value_from_uint(fixture->context,
 												 uint_test_in, NULL);
-	guint uint_test_out = seed_value_to_uint(state->eng->context,
+	guint uint_test_out = seed_value_to_uint(fixture->context,
 											 uint_test, NULL);
 	
 	g_assert(uint_test_in == uint_test_out);
@@ -28,9 +26,9 @@
 	// int to/from JS equality
 	
 	gint int_test_in = -54374;
-	SeedValue * int_test = seed_value_from_int(state->eng->context,
+	SeedValue * int_test = seed_value_from_int(fixture->context,
 											   int_test_in, NULL);
-	gint int_test_out = seed_value_to_int(state->eng->context,
+	gint int_test_out = seed_value_to_int(fixture->context,
 										  int_test, NULL);
 	
 	g_assert(int_test_in == int_test_out);
@@ -38,9 +36,9 @@
 	// char to/from JS equality
 	
 	gchar char_test_in = -126;
-	SeedValue * char_test = seed_value_from_char(state->eng->context,
+	SeedValue * char_test = seed_value_from_char(fixture->context,
 												 char_test_in, NULL);
-	gchar char_test_out = seed_value_to_char(state->eng->context,
+	gchar char_test_out = seed_value_to_char(fixture->context,
 											 char_test, NULL);
 	
 	g_assert(char_test_in == char_test_out);
@@ -48,9 +46,9 @@
 	// uchar to/from JS equality
 	
 	guchar uchar_test_in = 250;
-	SeedValue * uchar_test = seed_value_from_uchar(state->eng->context,
+	SeedValue * uchar_test = seed_value_from_uchar(fixture->context,
 												   uchar_test_in, NULL);
-	guchar uchar_test_out = seed_value_to_uchar(state->eng->context,
+	guchar uchar_test_out = seed_value_to_uchar(fixture->context,
 												uchar_test, NULL);
 	
 	g_assert(uchar_test_in == uchar_test_out);
@@ -58,9 +56,9 @@
 	// float to/from JS equality
 	
 	gfloat float_test_in = 1.618;
-	SeedValue * float_test = seed_value_from_float(state->eng->context,
+	SeedValue * float_test = seed_value_from_float(fixture->context,
 												   float_test_in, NULL);
-	gfloat float_test_out = seed_value_to_float(state->eng->context,
+	gfloat float_test_out = seed_value_to_float(fixture->context,
 												float_test, NULL);
 	
 	g_assert(float_test_in == float_test_out);

Modified: trunk/tests/c/main.c
==============================================================================
--- trunk/tests/c/main.c	(original)
+++ trunk/tests/c/main.c	Fri Jan  9 02:04:22 2009
@@ -15,10 +15,13 @@
 
 void test_simple_fixture_setup (TestSimpleFixture *fixture, gconstpointer data)
 {
+	TestSharedState * state = (TestSharedState *)data;
+	fixture->context = seed_context_create(state->eng->group, NULL);
 }
 
 void test_simple_fixture_teardown (TestSimpleFixture *fixture, gconstpointer data)
 {
+	seed_context_unref(fixture->context);
 }
 
 int main (int argc, char **argv)
@@ -41,6 +44,7 @@
 	shared_state->eng = eng;
 
 	TEST_SIMPLE ("/", basic);
+	TEST_SIMPLE ("/", closures);
 	TEST_SIMPLE ("/types/", basic_types);
 
 	return g_test_run ();

Modified: trunk/tests/c/test-common.h
==============================================================================
--- trunk/tests/c/test-common.h	(original)
+++ trunk/tests/c/test-common.h	Fri Jan  9 02:04:22 2009
@@ -4,9 +4,9 @@
  * argument */
 typedef struct _TestSharedState
 {
-  int	 *argc_addr;
-  char ***argv_addr;
-  SeedEngine * eng;
+	int *argc_addr;
+	char ***argv_addr;
+	SeedEngine * eng;
 } TestSharedState;
 
 
@@ -16,6 +16,6 @@
  * the test is finished. */
 typedef struct _TestSimpleFixture
 {
-  /**/
+	SeedContext * context;
 } TestSimpleFixture;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]