1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/** \file DynStringTest.c
* Unit tests for the dxfformat module
*/
#include <stdarg.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include <setjmp.h>
#include <cmocka.h>
#include <dynstring.h>
#include <dxfformat.h>
char *sProdNameUpper = "XTRKCAD";
long units;
static void BasicFormatting(void **state)
{
DynString string;
(void)state;
DynStringMalloc(&string, 0);
DxfLayerName(&string, sProdNameUpper, 0);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "8\nXTRKCAD0\n");
DxfLayerName(&string, sProdNameUpper, 99);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "8\nXTRKCAD99\n");
DxfFormatPosition(&string, 20, 1);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "20\n1.000000\n");
DxfFormatPosition(&string, 20, 1.23456789);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "20\n1.234568\n");
DxfFormatPosition(&string, 20, 1.23456712);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "20\n1.234567\n");
}
static void LineCommand(void **state)
{
DynString string;
(void)state;
DynStringMalloc(&string, 0);
DxfLineCommand( &string, 0, 1.0, 2.0, 1.1, 2.2, 1);
assert_string_equal(DynStringToCStr(&string),
DXF_INDENT "0\nLINE\n 8\nXTRKCAD0\n 10\n1.000000\n 20\n2.000000\n 11\n1.100000\n 21\n2.200000\n 6\nDASHED\n");
DynStringFree(&string);
}
static void CircleCommand(void **state)
{
DynString string;
(void)state;
DynStringMalloc(&string, 0);
DxfCircleCommand(&string, 0, 1.0, 2.0, 1.1, 1);
assert_string_equal(DynStringToCStr(&string),
DXF_INDENT "0\nCIRCLE\n 10\n1.000000\n 20\n2.000000\n 40\n1.100000\n 8\nXTRKCAD0\n 6\nDASHED\n");
DynStringFree(&string);
}
static void ArcCommand(void **state)
{
DynString string;
(void)state;
DynStringMalloc(&string, 0);
DxfArcCommand(&string, 0, 1.0, 2.0, 1.1, 10.0, 180.0, 1);
assert_string_equal(DynStringToCStr(&string),
DXF_INDENT "0\nARC\n 10\n1.000000\n 20\n2.000000\n 40\n1.100000\n 50\n10.000000\n 51\n190.000000\n 8\nXTRKCAD0\n 6\nDASHED\n");
DynStringFree(&string);
}
#define TESTSTRING "This is a dxf test string"
static void TextCommand(void **state)
{
DynString string;
(void)state;
DynStringMalloc(&string, 0);
DxfTextCommand(&string, 0, 10.0, 12.0, 144.0, TESTSTRING);
assert_string_equal(DynStringToCStr(&string),
DXF_INDENT "0\nTEXT\n 1\n" TESTSTRING "\n 10\n10.000000\n 20\n12.000000\n 40\n2.000000\n 8\nXTRKCAD0\n");
DynStringFree(&string);
}
static void Units(void **state)
{
DynString string;
(void)state;
DynStringMalloc(&string, 0);
/* test English units */
units = 0;
DxfUnits(&string);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "9\n$MEASUREMENT\n 70\n0\n" DXF_INDENT "9\n$INSUNITS\n 70\n1\n");
DxfFormatPosition(&string, 20, 1.23456789);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "20\n1.234568\n");
DynStringClear(&string);
DxfDimensionSize(&string, DXF_DIMTEXTSIZE);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "9\n$DIMTXT\n 40\n1.0\n");
/* test metric units */
units = 1;
DynStringClear(&string);
DxfUnits(&string);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "9\n$MEASUREMENT\n 70\n1\n" DXF_INDENT "9\n$INSUNITS\n 70\n4\n");
DxfFormatPosition(&string, 20, 1.23456789);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "20\n31.358024\n");
DynStringClear(&string);
DxfDimensionSize(&string, DXF_DIMTEXTSIZE);
assert_string_equal(DynStringToCStr(&string), DXF_INDENT "9\n$DIMTXT\n 40\n25.0\n");
}
int main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(BasicFormatting),
cmocka_unit_test(LineCommand),
cmocka_unit_test(CircleCommand),
cmocka_unit_test(ArcCommand),
cmocka_unit_test(TextCommand),
cmocka_unit_test(Units)
};
return cmocka_run_group_tests(tests, NULL, NULL);
}
|