Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added tests for bert_list_set.

  • Loading branch information...
commit 1403dbbc79a9b16c215c5d30dd18ad87e16ea42a 1 parent 9d96e16
Postmodern authored

Showing 3 changed files with 80 additions and 0 deletions. Show diff stats Hide diff stats

  1. +1 0  .gitignore
  2. +4 0 test/CMakeLists.txt
  3. +75 0 test/test_list_set.c
1  .gitignore
@@ -10,6 +10,7 @@ test/Testing
10 10 test/CTestTestfile.cmake
11 11 test/test_list_append
12 12 test/test_list_get
  13 +test/test_list_set
13 14 test/test_decode_small_int
14 15 test/test_decode_big_int
15 16 test/test_decode_small_bignum
4 test/CMakeLists.txt
@@ -10,6 +10,10 @@ add_executable(test_list_get test_list_get.c)
10 10 target_link_libraries(test_list_get test BERT)
11 11 add_test(decode_list_get test_list_get)
12 12
  13 +add_executable(test_list_set test_list_set.c)
  14 +target_link_libraries(test_list_set test BERT)
  15 +add_test(decode_list_set test_list_set)
  16 +
13 17 add_executable(test_decode_small_int test_decode_small_int.c)
14 18 target_link_libraries(test_decode_small_int test BERT)
15 19 add_test(decode_small_int test_decode_small_int)
75 test/test_list_set.c
... ... @@ -0,0 +1,75 @@
  1 +#include <bert/list.h>
  2 +
  3 +#include "test.h"
  4 +
  5 +#define EXPECTED_BEFORE 42
  6 +#define EXPECTED_AFTER 69
  7 +
  8 +bert_list_t *list;
  9 +
  10 +void test_set()
  11 +{
  12 + bert_data_t *data;
  13 +
  14 + if (!(data = bert_data_create_int(EXPECTED_AFTER)))
  15 + {
  16 + test_fail("malloc failed");
  17 + }
  18 +
  19 + if (!bert_list_set(list,0,data))
  20 + {
  21 + test_fail("bert_list_set could not find the first element");
  22 + }
  23 +
  24 + bert_data_t *first = list->head->data;
  25 +
  26 + if (first->type != bert_data_int)
  27 + {
  28 + test_fail("bert_list_set did not set an integer");
  29 + }
  30 +
  31 + if (first->integer != EXPECTED_AFTER)
  32 + {
  33 + test_fail("bert_list_set set %d as the first element, expected %d",first->integer,EXPECTED_AFTER);
  34 + }
  35 +}
  36 +
  37 +void test_set_out_of_bounds()
  38 +{
  39 + bert_data_t *data;
  40 +
  41 + if (!(data = bert_data_create_int(EXPECTED_AFTER)))
  42 + {
  43 + test_fail("malloc failed");
  44 + }
  45 +
  46 + if (bert_list_set(list,2,data))
  47 + {
  48 + test_fail("bert_list_set did not return 0 when setting out of bounds elements");
  49 + }
  50 +
  51 + bert_data_destroy(data);
  52 +}
  53 +
  54 +int main()
  55 +{
  56 + if (!(list = bert_list_create()))
  57 + {
  58 + test_fail("malloc failed");
  59 + }
  60 +
  61 + bert_data_t *data;
  62 +
  63 + if (!(data = bert_data_create_int(EXPECTED_BEFORE)))
  64 + {
  65 + test_fail("malloc failed");
  66 + }
  67 +
  68 + bert_list_append(list,data);
  69 +
  70 + test_set();
  71 + test_set_out_of_bounds();
  72 +
  73 + bert_list_destroy(list);
  74 + return 0;
  75 +}

0 comments on commit 1403dbb

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