From b0442e6d564862c61901cdc59f5071cc9d1c68a2 Mon Sep 17 00:00:00 2001
From: Tommy Olofsson <tommy.olofsson.90@gmail.com>
Date: Fri, 18 Apr 2014 14:35:12 +0200
Subject: [PATCH] Added a copy-test and added some uncommitted definitions.

---
 lib/c/test/more_types.lc       |  7 +++++++
 lib/c/test/test_labcomm_copy.c | 29 +++++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 2 deletions(-)
 create mode 100644 lib/c/test/more_types.lc

diff --git a/lib/c/test/more_types.lc b/lib/c/test/more_types.lc
new file mode 100644
index 0000000..91fb935
--- /dev/null
+++ b/lib/c/test/more_types.lc
@@ -0,0 +1,7 @@
+sample string S;
+sample int A[8];
+sample struct {
+  string s1;
+  string s2;
+} NS;
+sample string AS[_];
diff --git a/lib/c/test/test_labcomm_copy.c b/lib/c/test/test_labcomm_copy.c
index 6fc204b..9b9a0fd 100644
--- a/lib/c/test/test_labcomm_copy.c
+++ b/lib/c/test/test_labcomm_copy.c
@@ -59,6 +59,11 @@ static void handle_ns(more_types_NS *v, void *context)
   labcomm_copy_more_types_NS(labcomm_default_memory, context, v);
 }
 
+static void handle_as(more_types_AS *v, void *context)
+{
+  labcomm_copy_more_types_AS(labcomm_default_memory, context, v);
+}
+
 int main(int argc, char **argv)
 {
   struct labcomm_encoder *encoder;
@@ -80,6 +85,8 @@ int main(int argc, char **argv)
   more_types_S cache_s = NULL;
   more_types_NS ns;
   more_types_NS cache_ns;
+  more_types_AS as;
+  more_types_AS cache_as;
 
   fd = open(DATA_FILE, O_RDWR | O_CREAT | O_TRUNC, 0644);
   if (fd == -1)
@@ -132,9 +139,18 @@ int main(int argc, char **argv)
   labcomm_encode_more_types_S(encoder, &s);
 
   labcomm_encoder_register_more_types_NS(encoder);
-  ns.s = "this is a another string";
+  ns.s1 = "this is a string";
+  ns.s2 = "this is a another string";
   labcomm_encode_more_types_NS(encoder, &ns);
 
+  labcomm_encoder_register_more_types_AS(encoder);
+  as.n_0 = 3;
+  as.a = calloc(as.n_0, sizeof(as.a[0]));
+  as.a[0] = "string 0";
+  as.a[1] = "string 1";
+  as.a[2] = "string 2";
+  labcomm_encode_more_types_AS(encoder, &as);
+
   labcomm_encoder_free(encoder);
   encoder = NULL;
   lseek(fd, 0, SEEK_SET);
@@ -153,6 +169,7 @@ int main(int argc, char **argv)
   labcomm_decoder_register_more_types_A(decoder, handle_a, &cache_a);
   labcomm_decoder_register_more_types_S(decoder, handle_s, &cache_s);
   labcomm_decoder_register_more_types_NS(decoder, handle_ns, &cache_ns);
+  labcomm_decoder_register_more_types_AS(decoder, handle_as, &cache_as);
 
   while (labcomm_decoder_decode_one(decoder) > 0) ;
 
@@ -190,9 +207,15 @@ int main(int argc, char **argv)
   assert(!strcmp(cache_s, s));
   puts("S copied ok");
 
-  assert(!strcmp(cache_ns.s, ns.s));
+  assert(!strcmp(cache_ns.s1, ns.s1));
+  assert(!strcmp(cache_ns.s2, ns.s2));
   puts("NS copied ok");
 
+  for (int i = 0; i < as.n_0; i++)
+    assert(!strcmp(cache_as.a[i], as.a[i]));
+  free(as.a);
+  puts("AS copied ok");
+
   labcomm_decoder_free(decoder);
   close(fd);
   unlink(DATA_FILE);
@@ -213,4 +236,6 @@ int main(int argc, char **argv)
   puts("S deallocated ok");
   labcomm_copy_free_more_types_NS(labcomm_default_memory, &cache_ns);
   puts("NS deallocated ok");
+  labcomm_copy_free_more_types_AS(labcomm_default_memory, &cache_as);
+  puts("AS deallocated ok");
 }
-- 
GitLab