• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2015 Samsung Electronics Co., Ltd
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining
5  * a copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sublicense, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial
14  * portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #include "config.h"
27 
28 /**
29  * Tests of fixtures.
30  */
31 
32 #include <ctype.h>
33 #include <stdlib.h>
34 #include <stddef.h>
35 #include <string.h>
36 
37 #include "zunitc/zunitc.h"
38 
39 
40 
41 /* Use a simple string for a simplistic fixture */
42 static struct zuc_fixture fixture_minimal = {
43 	.data = "for all good men to",
44 };
45 
ZUC_TEST_F(fixture_minimal,just_as_is,data)46 ZUC_TEST_F(fixture_minimal, just_as_is, data)
47 {
48 	const char *str = data;
49 	ZUC_ASSERT_NOT_NULL(str);
50 
51 	ZUC_ASSERT_EQ(0, strcmp("for all good men to", str));
52 }
53 
54 /*
55  * Not important what or how data is manipulated, just that this function
56  * does something non-transparent to it.
57  */
58 static void *
setup_test_config(void * data)59 setup_test_config(void *data)
60 {
61 	int i;
62 	const char *str = data;
63 	char *upper = NULL;
64 	ZUC_ASSERTG_NOT_NULL(data, out);
65 
66 	upper = strdup(str);
67 	ZUC_ASSERTG_NOT_NULL(upper, out);
68 
69 	for (i = 0; upper[i]; ++i)
70 		upper[i] = (char)toupper(upper[i]);
71 
72 out:
73 	return upper;
74 }
75 
76 static void
teardown_test_config(void * data)77 teardown_test_config(void *data)
78 {
79 	ZUC_ASSERT_NOT_NULL(data);
80 	free(data);
81 }
82 
83 static struct zuc_fixture fixture_data0 = {
84 	.data = "Now is the time",
85 	.set_up = setup_test_config,
86 	.tear_down = teardown_test_config
87 };
88 
ZUC_TEST_F(fixture_data0,base,data)89 ZUC_TEST_F(fixture_data0, base, data)
90 {
91 	const char *str = data;
92 	ZUC_ASSERT_NOT_NULL(str);
93 
94 	ZUC_ASSERT_EQ(0, strcmp("NOW IS THE TIME", str));
95 }
96 
97 /* Use the same fixture for a second test. */
ZUC_TEST_F(fixture_data0,no_lower,data)98 ZUC_TEST_F(fixture_data0, no_lower, data)
99 {
100 	int i;
101 	const char *str = data;
102 	ZUC_ASSERT_NOT_NULL(str);
103 
104 	for (i = 0; str[i]; ++i)
105 		ZUC_ASSERT_EQ(0, islower(str[i]));
106 }
107