Skip to content
Browse files

Added tests for bert_list_set.

  • Loading branch information...
1 parent 9d96e16 commit 1403dbbc79a9b16c215c5d30dd18ad87e16ea42a @postmodern committed Jan 5, 2010
Showing with 80 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 test/CMakeLists.txt
  3. +75 −0 test/test_list_set.c
View
1 .gitignore
@@ -10,6 +10,7 @@ test/Testing
test/CTestTestfile.cmake
test/test_list_append
test/test_list_get
+test/test_list_set
test/test_decode_small_int
test/test_decode_big_int
test/test_decode_small_bignum
View
4 test/CMakeLists.txt
@@ -10,6 +10,10 @@ add_executable(test_list_get test_list_get.c)
target_link_libraries(test_list_get test BERT)
add_test(decode_list_get test_list_get)
+add_executable(test_list_set test_list_set.c)
+target_link_libraries(test_list_set test BERT)
+add_test(decode_list_set test_list_set)
+
add_executable(test_decode_small_int test_decode_small_int.c)
target_link_libraries(test_decode_small_int test BERT)
add_test(decode_small_int test_decode_small_int)
View
75 test/test_list_set.c
@@ -0,0 +1,75 @@
+#include <bert/list.h>
+
+#include "test.h"
+
+#define EXPECTED_BEFORE 42
+#define EXPECTED_AFTER 69
+
+bert_list_t *list;
+
+void test_set()
+{
+ bert_data_t *data;
+
+ if (!(data = bert_data_create_int(EXPECTED_AFTER)))
+ {
+ test_fail("malloc failed");
+ }
+
+ if (!bert_list_set(list,0,data))
+ {
+ test_fail("bert_list_set could not find the first element");
+ }
+
+ bert_data_t *first = list->head->data;
+
+ if (first->type != bert_data_int)
+ {
+ test_fail("bert_list_set did not set an integer");
+ }
+
+ if (first->integer != EXPECTED_AFTER)
+ {
+ test_fail("bert_list_set set %d as the first element, expected %d",first->integer,EXPECTED_AFTER);
+ }
+}
+
+void test_set_out_of_bounds()
+{
+ bert_data_t *data;
+
+ if (!(data = bert_data_create_int(EXPECTED_AFTER)))
+ {
+ test_fail("malloc failed");
+ }
+
+ if (bert_list_set(list,2,data))
+ {
+ test_fail("bert_list_set did not return 0 when setting out of bounds elements");
+ }
+
+ bert_data_destroy(data);
+}
+
+int main()
+{
+ if (!(list = bert_list_create()))
+ {
+ test_fail("malloc failed");
+ }
+
+ bert_data_t *data;
+
+ if (!(data = bert_data_create_int(EXPECTED_BEFORE)))
+ {
+ test_fail("malloc failed");
+ }
+
+ bert_list_append(list,data);
+
+ test_set();
+ test_set_out_of_bounds();
+
+ bert_list_destroy(list);
+ return 0;
+}

0 comments on commit 1403dbb

Please sign in to comment.
Something went wrong with that request. Please try again.