Skip to content

Commit 9737a2d

Browse files
adding test cases
1 parent fce3099 commit 9737a2d

File tree

2 files changed

+296
-0
lines changed

2 files changed

+296
-0
lines changed

code/tests/cases/test_parser.c

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* -----------------------------------------------------------------------------
3+
* Project: Fossil Logic
4+
*
5+
* This file is part of the Fossil Logic project, which aims to develop high-
6+
* performance, cross-platform applications and libraries. The code contained
7+
* herein is subject to the terms and conditions defined in the project license.
8+
*
9+
* Author: Michael Gene Brockus (Dreamer)
10+
* Date: 07/01/2024
11+
*
12+
* Copyright (C) 2024 Fossil Logic. All rights reserved.
13+
* -----------------------------------------------------------------------------
14+
*/
15+
#include <fossil/test/framework.h>
16+
#include <fossil/io/framework.h>
17+
18+
19+
// * * * * * * * * * * * * * * * * * * * * * * * *
20+
// * Fossil Logic Test Utilites
21+
// * * * * * * * * * * * * * * * * * * * * * * * *
22+
// Setup steps for things like test fixtures and
23+
// mock objects are set here.
24+
// * * * * * * * * * * * * * * * * * * * * * * * *
25+
26+
// Define the test suite and add test cases
27+
FOSSIL_TEST_SUITE(c_parser_suite);
28+
29+
// Setup function for the test suite
30+
FOSSIL_SETUP(c_parser_suite) {
31+
// Setup code here
32+
}
33+
34+
// Teardown function for the test suite
35+
FOSSIL_TEARDOWN(c_parser_suite) {
36+
// Teardown code here
37+
}
38+
39+
// * * * * * * * * * * * * * * * * * * * * * * * *
40+
// * Fossil Logic Test Cases
41+
// * * * * * * * * * * * * * * * * * * * * * * * *
42+
// The test cases below are provided as samples, inspired
43+
// by the Meson build system's approach of using test cases
44+
// as samples for library usage.
45+
// * * * * * * * * * * * * * * * * * * * * * * * *
46+
47+
FOSSIL_TEST_CASE(c_create_palette) {
48+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
49+
FOSSIL_TEST_ASSUME(palette != NULL, "Palette should be created");
50+
FOSSIL_TEST_ASSUME(strcmp(palette->name, "test_palette") == 0, "Palette name should be 'test_palette'");
51+
FOSSIL_TEST_ASSUME(strcmp(palette->description, "Test Description") == 0, "Palette description should be 'Test Description'");
52+
FOSSIL_TEST_ASSUME(palette->commands == NULL, "Palette commands should be NULL");
53+
fossil_io_parser_free(palette);
54+
} // end case
55+
56+
FOSSIL_TEST_CASE(c_add_command) {
57+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
58+
fossil_io_parser_command_t *command = fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
59+
FOSSIL_TEST_ASSUME(command != NULL, "Command should be added");
60+
FOSSIL_TEST_ASSUME(strcmp(command->name, "test_command") == 0, "Command name should be 'test_command'");
61+
FOSSIL_TEST_ASSUME(strcmp(command->description, "Test Command Description") == 0, "Command description should be 'Test Command Description'");
62+
FOSSIL_TEST_ASSUME(command->arguments == NULL, "Command arguments should be NULL");
63+
FOSSIL_TEST_ASSUME(palette->commands == command, "Palette commands should include the new command");
64+
fossil_io_parser_free(palette);
65+
} // end case
66+
67+
FOSSIL_TEST_CASE(c_add_argument) {
68+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
69+
fossil_io_parser_command_t *command = fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
70+
fossil_io_parser_argument_t *argument = fossil_io_parser_add_argument(command, "test_arg", FOSSIL_io_PARSER_STRING, NULL, 0);
71+
FOSSIL_TEST_ASSUME(argument != NULL, "Argument should be added");
72+
FOSSIL_TEST_ASSUME(strcmp(argument->name, "test_arg") == 0, "Argument name should be 'test_arg'");
73+
FOSSIL_TEST_ASSUME(argument->type == FOSSIL_io_PARSER_STRING, "Argument type should be STRING");
74+
FOSSIL_TEST_ASSUME(argument->value == NULL, "Argument value should be NULL");
75+
FOSSIL_TEST_ASSUME(command->arguments == argument, "Command arguments should include the new argument");
76+
fossil_io_parser_free(palette);
77+
} // end case
78+
79+
FOSSIL_TEST_CASE(c_parse_command) {
80+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
81+
fossil_io_parser_command_t *command = fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
82+
fossil_io_parser_add_argument(command, "test_arg", FOSSIL_io_PARSER_STRING, NULL, 0);
83+
84+
char *argv[] = {"program", "test_command", "test_arg", "test_value"};
85+
fossil_io_parser_parse(palette, 4, argv);
86+
87+
FOSSIL_TEST_ASSUME(command->arguments->value != NULL, "Argument value should be set");
88+
fossil_io_parser_free(palette);
89+
} // end case
90+
91+
FOSSIL_TEST_CASE(c_free_palette) {
92+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
93+
ASSUME_NOT_CNULL(palette);
94+
fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
95+
fossil_io_parser_free(palette);
96+
// No explicit assumptions here, just ensuring no memory leaks or crashes
97+
} // end case
98+
99+
// * * * * * * * * * * * * * * * * * * * * * * * *
100+
// * Fossil Logic Test Pool
101+
// * * * * * * * * * * * * * * * * * * * * * * * *
102+
FOSSIL_TEST_GROUP(c_parser_test_cases) {
103+
FOSSIL_TEST_ADD(c_parser_suite, c_create_palette);
104+
FOSSIL_TEST_ADD(c_parser_suite, c_add_command);
105+
FOSSIL_TEST_ADD(c_parser_suite, c_add_argument);
106+
FOSSIL_TEST_ADD(c_parser_suite, c_parse_command);
107+
FOSSIL_TEST_ADD(c_parser_suite, c_free_palette);
108+
109+
FOSSIL_TEST_REGISTER(c_parser_suite);
110+
} // end of group

code/tests/cases/test_parser.cpp

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
/*
2+
* -----------------------------------------------------------------------------
3+
* Project: Fossil Logic
4+
*
5+
* This file is part of the Fossil Logic project, which aims to develop high-
6+
* performance, cross-platform applications and libraries. The code contained
7+
* herein is subject to the terms and conditions defined in the project license.
8+
*
9+
* Author: Michael Gene Brockus (Dreamer)
10+
* Date: 07/01/2024
11+
*
12+
* Copyright (C) 2024 Fossil Logic. All rights reserved.
13+
* -----------------------------------------------------------------------------
14+
*/
15+
#include <fossil/test/framework.h>
16+
#include <fossil/io/framework.h>
17+
#include <vector>
18+
#include <string>
19+
20+
21+
// * * * * * * * * * * * * * * * * * * * * * * * *
22+
// * Fossil Logic Test Utilites
23+
// * * * * * * * * * * * * * * * * * * * * * * * *
24+
// Setup steps for things like test fixtures and
25+
// mock objects are set here.
26+
// * * * * * * * * * * * * * * * * * * * * * * * *
27+
28+
// Define the test suite and add test cases
29+
FOSSIL_TEST_SUITE(cpp_parser_suite);
30+
31+
// Setup function for the test suite
32+
FOSSIL_SETUP(cpp_parser_suite) {
33+
// Setup code here
34+
}
35+
36+
// Teardown function for the test suite
37+
FOSSIL_TEARDOWN(cpp_parser_suite) {
38+
// Teardown code here
39+
}
40+
41+
// * * * * * * * * * * * * * * * * * * * * * * * *
42+
// * Fossil Logic Test Cases
43+
// * * * * * * * * * * * * * * * * * * * * * * * *
44+
// The test cases below are provided as samples, inspired
45+
// by the Meson build system's approach of using test cases
46+
// as samples for library usage.
47+
// * * * * * * * * * * * * * * * * * * * * * * * *
48+
49+
FOSSIL_TEST_CASE(cpp_create_palette) {
50+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
51+
FOSSIL_TEST_ASSUME(palette != NULL, "Palette should be created");
52+
FOSSIL_TEST_ASSUME(strcmp(palette->name, "test_palette") == 0, "Palette name should be 'test_palette'");
53+
FOSSIL_TEST_ASSUME(strcmp(palette->description, "Test Description") == 0, "Palette description should be 'Test Description'");
54+
FOSSIL_TEST_ASSUME(palette->commands == NULL, "Palette commands should be NULL");
55+
fossil_io_parser_free(palette);
56+
} // end case
57+
58+
FOSSIL_TEST_CASE(cpp_add_command) {
59+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
60+
fossil_io_parser_command_t *command = fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
61+
FOSSIL_TEST_ASSUME(command != NULL, "Command should be added");
62+
FOSSIL_TEST_ASSUME(strcmp(command->name, "test_command") == 0, "Command name should be 'test_command'");
63+
FOSSIL_TEST_ASSUME(strcmp(command->description, "Test Command Description") == 0, "Command description should be 'Test Command Description'");
64+
FOSSIL_TEST_ASSUME(command->arguments == NULL, "Command arguments should be NULL");
65+
FOSSIL_TEST_ASSUME(palette->commands == command, "Palette commands should include the new command");
66+
fossil_io_parser_free(palette);
67+
} // end case
68+
69+
FOSSIL_TEST_CASE(cpp_add_argument) {
70+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
71+
fossil_io_parser_command_t *command = fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
72+
fossil_io_parser_argument_t *argument = fossil_io_parser_add_argument(command, "test_arg", FOSSIL_io_PARSER_STRING, NULL, 0);
73+
FOSSIL_TEST_ASSUME(argument != NULL, "Argument should be added");
74+
FOSSIL_TEST_ASSUME(strcmp(argument->name, "test_arg") == 0, "Argument name should be 'test_arg'");
75+
FOSSIL_TEST_ASSUME(argument->type == FOSSIL_io_PARSER_STRING, "Argument type should be STRING");
76+
FOSSIL_TEST_ASSUME(argument->value == NULL, "Argument value should be NULL");
77+
FOSSIL_TEST_ASSUME(command->arguments == argument, "Command arguments should include the new argument");
78+
fossil_io_parser_free(palette);
79+
} // end case
80+
81+
FOSSIL_TEST_CASE(cpp_parse_command) {
82+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
83+
fossil_io_parser_command_t *command = fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
84+
fossil_io_parser_add_argument(command, "test_arg", FOSSIL_io_PARSER_STRING, NULL, 0);
85+
86+
std::vector<std::string> argv = {"program", "test_command", "test_arg", "test_value"};
87+
std::vector<const char*> argv_cstr;
88+
for (const auto& arg : argv) {
89+
argv_cstr.push_back(arg.c_str());
90+
}
91+
fossil_io_parser_parse(palette, 4, const_cast<char**>(argv_cstr.data()));
92+
93+
FOSSIL_TEST_ASSUME(command->arguments->value != NULL, "Argument value should be set");
94+
fossil_io_parser_free(palette);
95+
} // end case
96+
97+
FOSSIL_TEST_CASE(cpp_free_palette) {
98+
fossil_io_parser_palette_t *palette = fossil_io_parser_create_palette("test_palette", "Test Description");
99+
100+
ASSUME_NOT_CNULL(palette);
101+
fossil_io_parser_add_command(palette, "test_command", "Test Command Description");
102+
fossil_io_parser_free(palette);
103+
// No explicit assumptions here, just ensuring no memory leaks or crashes
104+
} // end case
105+
106+
FOSSIL_TEST_CASE(cpp_wrapper_create_palette) {
107+
fossil::io::Parser parser;
108+
fossil_io_parser_palette_t *palette = parser.create_palette("wrapper_palette", "Wrapper Test Description");
109+
FOSSIL_TEST_ASSUME(palette != NULL, "Palette should be created");
110+
FOSSIL_TEST_ASSUME(strcmp(palette->name, "wrapper_palette") == 0, "Palette name should be 'wrapper_palette'");
111+
FOSSIL_TEST_ASSUME(strcmp(palette->description, "Wrapper Test Description") == 0, "Palette description should be 'Wrapper Test Description'");
112+
FOSSIL_TEST_ASSUME(palette->commands == NULL, "Palette commands should be NULL");
113+
parser.free(palette);
114+
} // end case
115+
116+
FOSSIL_TEST_CASE(cpp_wrapper_add_command) {
117+
fossil::io::Parser parser;
118+
fossil_io_parser_palette_t *palette = parser.create_palette("wrapper_palette", "Wrapper Test Description");
119+
fossil_io_parser_command_t *command = parser.add_command(palette, "wrapper_command", "Wrapper Command Description");
120+
FOSSIL_TEST_ASSUME(command != NULL, "Command should be added");
121+
FOSSIL_TEST_ASSUME(strcmp(command->name, "wrapper_command") == 0, "Command name should be 'wrapper_command'");
122+
FOSSIL_TEST_ASSUME(strcmp(command->description, "Wrapper Command Description") == 0, "Command description should be 'Wrapper Command Description'");
123+
FOSSIL_TEST_ASSUME(command->arguments == NULL, "Command arguments should be NULL");
124+
FOSSIL_TEST_ASSUME(palette->commands == command, "Palette commands should include the new command");
125+
parser.free(palette);
126+
} // end case
127+
128+
FOSSIL_TEST_CASE(cpp_wrapper_add_argument) {
129+
fossil::io::Parser parser;
130+
fossil_io_parser_palette_t *palette = parser.create_palette("wrapper_palette", "Wrapper Test Description");
131+
fossil_io_parser_command_t *command = parser.add_command(palette, "wrapper_command", "Wrapper Command Description");
132+
fossil_io_parser_argument_t *argument = parser.add_argument(command, "wrapper_arg", FOSSIL_io_PARSER_STRING, NULL, 0);
133+
FOSSIL_TEST_ASSUME(argument != NULL, "Argument should be added");
134+
FOSSIL_TEST_ASSUME(strcmp(argument->name, "wrapper_arg") == 0, "Argument name should be 'wrapper_arg'");
135+
FOSSIL_TEST_ASSUME(argument->type == FOSSIL_io_PARSER_STRING, "Argument type should be STRING");
136+
FOSSIL_TEST_ASSUME(argument->value == NULL, "Argument value should be NULL");
137+
FOSSIL_TEST_ASSUME(command->arguments == argument, "Command arguments should include the new argument");
138+
parser.free(palette);
139+
} // end case
140+
141+
FOSSIL_TEST_CASE(cpp_wrapper_parse_command) {
142+
fossil::io::Parser parser;
143+
fossil_io_parser_palette_t *palette = parser.create_palette("wrapper_palette", "Wrapper Test Description");
144+
fossil_io_parser_command_t *command = parser.add_command(palette, "wrapper_command", "Wrapper Command Description");
145+
parser.add_argument(command, "wrapper_arg", FOSSIL_io_PARSER_STRING, NULL, 0);
146+
147+
std::vector<std::string> argv = {"program", "wrapper_command", "wrapper_arg", "wrapper_value"};
148+
std::vector<const char*> argv_cstr;
149+
for (const auto& arg : argv) {
150+
argv_cstr.push_back(arg.c_str());
151+
}
152+
parser.parse(palette, 4, const_cast<char**>(argv_cstr.data()));
153+
154+
FOSSIL_TEST_ASSUME(command->arguments->value != NULL, "Argument value should be set");
155+
parser.free(palette);
156+
} // end case
157+
158+
FOSSIL_TEST_CASE(cpp_wrapper_free_palette) {
159+
fossil::io::Parser parser;
160+
fossil_io_parser_palette_t *palette = parser.create_palette("wrapper_palette", "Wrapper Test Description");
161+
162+
ASSUME_NOT_CNULL(palette);
163+
parser.add_command(palette, "wrapper_command", "Wrapper Command Description");
164+
parser.free(palette);
165+
// No explicit assumptions here, just ensuring no memory leaks or crashes
166+
} // end case
167+
168+
169+
// * * * * * * * * * * * * * * * * * * * * * * * *
170+
// * Fossil Logic Test Pool
171+
// * * * * * * * * * * * * * * * * * * * * * * * *
172+
173+
FOSSIL_TEST_GROUP(cpp_parser_test_cases) {
174+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_create_palette);
175+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_add_command);
176+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_add_argument);
177+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_parse_command);
178+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_free_palette);
179+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_create_palette);
180+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_add_command);
181+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_add_argument);
182+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_parse_command);
183+
FOSSIL_TEST_ADD(cpp_parser_suite, cpp_wrapper_free_palette);
184+
185+
FOSSIL_TEST_REGISTER(cpp_parser_suite);
186+
} // end of group

0 commit comments

Comments
 (0)