Permalink
Browse files

Build, test environment improved.

  • Loading branch information...
1 parent 6f0ad53 commit c9418239ae4e09a728702c9388d42f6a0e2a90cd _why committed Feb 27, 2003
Showing with 176 additions and 24 deletions.
  1. +5 −0 Makefile.am
  2. +7 −0 bootstrap
  3. +33 −0 configure.in
  4. +5 −0 lib/Makefile.am
  5. +63 −0 lib/syck.c
  6. +17 −1 lib/syck.h
  7. +0 −21 tests/AllTests.c
  8. +39 −2 tests/Basic.c
  9. +7 −0 tests/Makefile.am
View
5 Makefile.am
@@ -0,0 +1,5 @@
+#
+# I feel like saying, "The magic happens here!" But it doesn't.
+#
+SUBDIRS = lib tests
+
View
7 bootstrap
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+set -x
+aclocal
+autoheader
+automake --foreign --add-missing --copy
+autoconf
View
33 configure.in
@@ -0,0 +1,33 @@
+# Process this file with autoconf to produce a configure script.
+AC_INIT(SYCK, 0.01)
+
+AC_PREREQ(2.50)
+
+AC_CONFIG_AUX_DIR(config)
+AC_CONFIG_HEADERS([config.h])
+AM_INIT_AUTOMAKE(syck, 0.01)
+
+# Checks for programs.
+AC_PROG_AWK
+AC_PROG_CC
+AC_PROG_INSTALL
+AC_PROG_LN_S
+AC_PROG_RANLIB
+AC_PROG_MAKE_SET
+
+# Checks for libraries.
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS(alloca.h stdlib.h string.h)
+
+# Checks for typedefs, structures, and compiler characteristics.
+
+# Checks for library functions.
+AC_FUNC_MALLOC
+AC_FUNC_VPRINTF
+
+AC_CONFIG_FILES([Makefile
+ lib/Makefile
+ tests/Makefile])
+AC_OUTPUT
View
5 lib/Makefile.am
@@ -0,0 +1,5 @@
+
+INCLUDES = -I$(top_builddir) -I$(top_srcdir)
+
+lib_LIBRARIES = libsyck.a
+libsyck_a_SOURCES = syck.c
View
63 lib/syck.c
@@ -70,6 +70,13 @@ new_str_node( char *str )
return n;
}
+char *
+read_str_node( struct SyckNode *n )
+{
+ //assert( n != NULL );
+ return n->data.str;
+}
+
struct SyckNode *
new_map_node( struct SyckNode *key, struct SyckNode *value )
{
@@ -99,6 +106,62 @@ add_map_pair( struct SyckNode *map, struct SyckNode *key, struct SyckNode *value
m->values[idx] = value;
}
+struct SyckNode *
+read_map_node( struct SyckNode *map, enum map_part p, long idx )
+{
+ struct SyckMap *m;
+
+ //assert( map != NULL );
+ m = map->data.pairs;
+ //assert( m != NULL );
+ if ( p == map_key )
+ {
+ return m->keys[idx];
+ }
+ else
+ {
+ return m->values[idx];
+ }
+}
+
+struct SyckNode *
+new_seq_node( struct SyckNode *value )
+{
+ struct SyckNode *n;
+
+ n = alloc_seq_node();
+ add_seq_item( n, value );
+
+ return n;
+}
+
+void
+add_seq_item( struct SyckNode *arr, struct SyckNode *value )
+{
+ struct SyckSeq *s;
+ long idx;
+
+ //assert( arr != NULL );
+ //assert( arr->data.list != NULL );
+
+ s = arr->data.list;
+ idx = s->capa;
+ s->capa += 1;
+ REALLOC_N( s->items, struct SyckNode *, s->capa );
+ s->items[idx] = value;
+}
+
+struct SyckNode *
+read_seq_node( struct SyckNode *seq, long idx )
+{
+ struct SyckSeq *s;
+
+ //assert( seq != NULL );
+ s = seq->data.list;
+ //assert( s != NULL );
+ return s->items[idx];
+}
+
//static char *
//syckp_read( prsr, len )
// struct SyckParser *prsr;
View
18 lib/syck.h
@@ -45,18 +45,29 @@ enum syck_kind_tag {
str_kind
};
+enum map_part {
+ map_key,
+ map_value
+};
+
struct SyckNode {
+ // Underlying kind
enum syck_kind_tag kind;
+ // Fully qualified tag-uri for type
+ char *type_id;
union {
+ // Storage for map data
struct SyckMap {
struct SyckNode **keys;
struct SyckNode **values;
long capa;
} *pairs;
+ // Storage for sequence data
struct SyckSeq {
- struct SyckNode **values;
+ struct SyckNode **items;
long capa;
} *list;
+ // Storage for string data
char *str;
} data;
};
@@ -75,8 +86,13 @@ struct SyckNode {
// API prototypes
//
struct SyckNode *new_str_node( char *str );
+char *read_str_node( struct SyckNode *n );
struct SyckNode *new_map_node( struct SyckNode *key, struct SyckNode *value );
void add_map_pair( struct SyckNode *map, struct SyckNode *key, struct SyckNode *value );
+struct SyckNode *read_map_node( struct SyckNode *map, enum map_part p, long idx );
+struct SyckNode *new_seq_node( struct SyckNode *value );
+void add_seq_item( struct SyckNode *arr, struct SyckNode *value );
+struct SyckNode *read_seq_node( struct SyckNode *seq, long idx );
#if defined(__cplusplus)
} /* extern "C" { */
View
21 tests/AllTests.c
@@ -1,21 +0,0 @@
-#include "CuTest.h"
-
-CuSuite* SyckGetSuite();
-
-void RunAllTests(void)
-{
- CuString *output = CuStringNew();
- CuSuite* suite = CuSuiteNew();
-
- CuSuiteAddSuite(suite, SyckGetSuite());
-
- CuSuiteRun(suite);
- CuSuiteSummary(suite, output);
- CuSuiteDetails(suite, output);
- printf("%s\n", output->buffer);
-}
-
-int main(void)
-{
- RunAllTests();
-}
View
41 tests/Basic.c
@@ -23,12 +23,33 @@ TestSyckNodeAlloc( CuTest *tc )
CuAssert( tc, "Allocated 'str' node reporting as 'seq'.", n->kind != seq_kind );
CuAssert( tc, "Allocated 'str' node reporting as 'map'.", n->kind != map_kind );
CuAssert( tc, "Allocated 'str' not reporting as 'str'.", n->kind == str_kind );
- CuAssertStrEquals( tc, "YAML", n->data.str );
+ CuAssertStrEquals( tc, "YAML", read_str_node( n ) );
free( n );
}
//
+// Test building a simple sequence
+//
+void
+TestSyckSeqAlloc( CuTest *tc )
+{
+ struct SyckNode *n, *n1, *n2;
+
+ n1 = new_str_node( "ONE" );
+ n2 = new_str_node( "TWO" );
+ n = new_seq_node( n1 );
+ add_seq_item( n, n2 );
+
+ CuAssertStrEquals( tc, "ONE", read_str_node( read_seq_node( n, 0 ) ) );
+ CuAssertStrEquals( tc, "TWO", read_str_node( read_seq_node( n, 1 ) ) );
+
+ free( n2 );
+ free( n1 );
+ free( n );
+}
+
+//
// Test building a simple map
//
void
@@ -40,7 +61,8 @@ TestSyckMapAlloc( CuTest *tc )
n2 = new_str_node( "VALUE" );
n = new_map_node( n1, n2 );
- CuAssertStrEquals( tc, "VALUE", n->data.pairs->values[0]->data.str );
+ CuAssertStrEquals( tc, "VALUE", read_str_node( read_map_node( n, map_value, 0 ) ) );
+ CuAssertStrEquals( tc, "KEY", read_str_node( read_map_node( n, map_key, 0 ) ) );
free( n2 );
free( n1 );
@@ -52,6 +74,21 @@ SyckGetSuite()
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST( suite, TestSyckNodeAlloc );
+ SUITE_ADD_TEST( suite, TestSyckSeqAlloc );
SUITE_ADD_TEST( suite, TestSyckMapAlloc );
return suite;
}
+
+int main(void)
+{
+ CuString *output = CuStringNew();
+ CuSuite* suite = CuSuiteNew();
+
+ CuSuiteAddSuite(suite, SyckGetSuite());
+
+ CuSuiteRun(suite);
+ CuSuiteSummary(suite, output);
+ CuSuiteDetails(suite, output);
+ printf("%s\n", output->buffer);
+ return suite->failCount;
+}
View
7 tests/Makefile.am
@@ -0,0 +1,7 @@
+TESTS = test-basic
+INCLUDES = -I$(top_srcdir)/lib
+LDFLAGS = -L$(top_srcdir)/lib
+
+bin_PROGRAMS = test-basic
+test_basic_SOURCES = Basic.c CuTest.c
+test_basic_LDADD = -lsyck

0 comments on commit c941823

Please sign in to comment.