Line data Source code
1 : /*
2 : test_dyn_buffer.c
3 : Created by Danny Goossen, Gioxa Ltd on 26/3/17.
4 :
5 : MIT License
6 :
7 : Copyright (c) 2017 deployctl, Gioxa Ltd.
8 :
9 : Permission is hereby granted, free of charge, to any person obtaining a copy
10 : of this software and associated documentation files (the "Software"), to deal
11 : in the Software without restriction, including without limitation the rights
12 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 : copies of the Software, and to permit persons to whom the Software is
14 : furnished to do so, subject to the following conditions:
15 :
16 : The above copyright notice and this permission notice shall be included in all
17 : copies or substantial portions of the Software.
18 :
19 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 : SOFTWARE.
26 :
27 : */
28 :
29 : #include <check.h>
30 :
31 : #include "../src/deployd.h"
32 :
33 : struct MemoryStruct mem;
34 :
35 5 : static void setup(void)
36 : {
37 5 : init_dynamicbuf( &mem);
38 5 : }
39 :
40 1 : static void teardown(void)
41 : {
42 1 : free(mem.memory);
43 1 : }
44 :
45 1 : START_TEST(check_WriteMemoryCallback)
46 : {
47 1 : printf("check_WriteMemoryCallback\n");
48 1 : size_t res=0;
49 1 : res=WriteMemoryCallback("0123456789", 10, 1,&mem);
50 1 : ck_assert_int_eq(res, 10);
51 2 : ck_assert_ptr_ne(mem.memory, NULL);
52 2 : ck_assert_int_eq(mem.size, 10);
53 2 : ck_assert_str_eq("0123456789", mem.memory);
54 1 : res=WriteMemoryCallback("0123456789", 3, 2,&mem);
55 2 : ck_assert_int_eq(res, 6);
56 2 : ck_assert_int_eq(mem.size, 16);
57 2 : ck_assert_str_eq("0123456789012345", mem.memory);
58 : }
59 1 : END_TEST
60 :
61 1 : START_TEST(check_Writedynamicbuf)
62 : {
63 1 : printf("check_Writedynamicbuf\n");
64 1 : size_t res=0;
65 1 : res=Writedynamicbuf("0123456789", &mem);
66 1 : ck_assert_int_eq(res, 10);
67 2 : ck_assert_ptr_ne(mem.memory, NULL);
68 2 : ck_assert_int_eq(mem.size, 10);
69 2 : ck_assert_str_eq("0123456789", mem.memory);
70 1 : res=Writedynamicbuf("01234", &mem);
71 2 : ck_assert_int_eq(res, 5);
72 2 : ck_assert_int_eq(mem.size, 15);
73 2 : ck_assert_str_eq("012345678901234", mem.memory);
74 : }
75 1 : END_TEST
76 :
77 1 : START_TEST(check_Writedynamicbuf_n)
78 : {
79 1 : printf("check_Writedynamicbuf_n");
80 1 : size_t res=0;
81 1 : res=Writedynamicbuf_n("0123456789", 10, &mem);
82 1 : ck_assert_int_eq(res, 10);
83 2 : ck_assert_ptr_ne(mem.memory, NULL);
84 2 : ck_assert_int_eq(mem.size, 10);
85 2 : ck_assert_str_eq("0123456789", mem.memory);
86 1 : res=Writedynamicbuf_n("0123456789", 5, &mem);
87 2 : ck_assert_int_eq(res, 5);
88 2 : ck_assert_int_eq(mem.size, 15);
89 2 : ck_assert_str_eq("012345678901234", mem.memory);
90 : }
91 1 : END_TEST
92 :
93 1 : START_TEST(check_init_dynamicbuf)
94 : {
95 1 : printf("check_init_dynamicbuf\n");
96 1 : ck_assert_ptr_ne(mem.memory, NULL);
97 2 : ck_assert_int_eq(mem.size, 0);
98 2 : ck_assert_int_eq( mem.memory[0],0);
99 : }
100 1 : END_TEST
101 :
102 5 : Suite * dyn_buffer_suite(void)
103 : {
104 :
105 : Suite *s;
106 : TCase *tc_core;
107 : //TCase *tc_progress;
108 5 : s = suite_create("test_dyn_buffer");
109 : /* Core test case */
110 5 : tc_core = tcase_create("Core");
111 : //tcase_add_checked_fixture(tc_core, setup, teardown);
112 5 : tcase_add_unchecked_fixture(tc_core, setup, teardown);
113 5 : tcase_set_timeout(tc_core,15);
114 5 : tcase_add_test(tc_core, check_init_dynamicbuf);
115 5 : tcase_add_test(tc_core, check_Writedynamicbuf);
116 5 : tcase_add_test(tc_core, check_Writedynamicbuf_n);
117 5 : tcase_add_test(tc_core, check_WriteMemoryCallback);
118 5 : suite_add_tcase(s, tc_core);
119 5 : return s;
120 : }
121 :
122 :
123 5 : int main(void)
124 : {
125 : int number_failed;
126 : Suite *s;
127 : SRunner *sr;
128 :
129 5 : s = dyn_buffer_suite();
130 5 : sr = srunner_create(s);
131 5 : srunner_run_all(sr, CK_VERBOSE);
132 1 : number_failed = srunner_ntests_failed(sr);
133 1 : srunner_free(sr);
134 1 : return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
135 : }
|