Skip to content

Commit 40929d0

Browse files
add sanity test
1 parent 57dabca commit 40929d0

File tree

4 files changed

+235
-5
lines changed

4 files changed

+235
-5
lines changed

code/logic/sanity.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@
2222
#include <fcntl.h>
2323
#endif
2424

25-
int fossil_sys_call_execute(const char *command) {
25+
int pizza_sys_call_execute(const char *command) {
2626
#ifdef _WIN32
2727
return system(command); // On Windows, use the system function to execute the command.
2828
#else
2929
return system(command); // On Unix-like systems, use the system function to execute the command.
3030
#endif
3131
}
3232

33-
int fossil_sys_call_getpid(void) {
33+
int pizza_sys_call_getpid(void) {
3434
#ifdef _WIN32
3535
return GetCurrentProcessId(); // On Windows, use the GetCurrentProcessId function to get the process ID.
3636
#else
3737
return getpid(); // On Unix-like systems, use the getpid function to get the process ID.
3838
#endif
3939
}
4040

41-
void fossil_sys_call_sleep(int milliseconds) {
41+
void pizza_sys_call_sleep(int milliseconds) {
4242
#ifdef _WIN32
4343
Sleep(milliseconds); // On Windows, use the Sleep function to sleep for the specified number of milliseconds.
4444
#else
4545
sleep(milliseconds * 1000); // On Unix-like systems, use the usleep function to sleep for the specified number of microseconds.
4646
#endif
4747
}
4848

49-
int fossil_sys_call_create_file(const char *filename) {
49+
int pizza_sys_call_create_file(const char *filename) {
5050
#ifdef _WIN32
5151
HANDLE hFile = CreateFileA(filename, GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
5252
if (hFile == INVALID_HANDLE_VALUE) return -1; // If the file handle is invalid, return an error code.
@@ -59,3 +59,29 @@ int fossil_sys_call_create_file(const char *filename) {
5959
return 0; // Return success.
6060
#endif
6161
}
62+
63+
int fossil_sanity_sys_execute(const char* command) {
64+
return pizza_sys_call_execute(command);
65+
}
66+
67+
int fossil_sanity_sys_getpid(void) {
68+
return pizza_sys_call_getpid();
69+
}
70+
71+
void fossil_sanity_sys_sleep(int milliseconds) {
72+
pizza_sys_call_sleep(milliseconds);
73+
}
74+
75+
int fossil_sanity_sys_create_file(const char* filename) {
76+
return pizza_sys_call_create_file(filename);
77+
}
78+
79+
int fossil_sanity_sys_file_exists(const char* filename) {
80+
#ifdef _WIN32
81+
struct _stat buffer;
82+
return (_stat(filename, &buffer) == 0); // On Windows, use the _stat function to check if the file exists.
83+
#else
84+
struct stat buffer;
85+
return (stat(filename, &buffer) == 0); // On Unix-like systems, use the stat function to check if the file exists.
86+
#endif
87+
}

code/tests/cases/test_sanity.c

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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: 04/05/2014
11+
*
12+
* Copyright (C) 2014-2025 Fossil Logic. All rights reserved.
13+
* -----------------------------------------------------------------------------
14+
*/
15+
#include <fossil/pizza/framework.h>
16+
17+
// * * * * * * * * * * * * * * * * * * * * * * * *
18+
// * Fossil Logic Test Utilites
19+
// * * * * * * * * * * * * * * * * * * * * * * * *
20+
// Setup steps for things like test fixtures and
21+
// mock objects are set here.
22+
// * * * * * * * * * * * * * * * * * * * * * * * *
23+
24+
// Define the test suite and add test cases
25+
FOSSIL_SUITE(c_sanity_suite);
26+
27+
// Setup function for the test suite
28+
FOSSIL_SETUP(c_sanity_suite) {
29+
// Setup code here
30+
}
31+
32+
// Teardown function for the test suite
33+
FOSSIL_TEARDOWN(c_sanity_suite) {
34+
// Teardown code here
35+
}
36+
37+
// * * * * * * * * * * * * * * * * * * * * * * * *
38+
// * Fossil Logic Test Cases
39+
// * * * * * * * * * * * * * * * * * * * * * * * *
40+
// The test cases below are provided as samples, inspired
41+
// by the Meson build system's approach of using test cases
42+
// as samples for library usage.
43+
// * * * * * * * * * * * * * * * * * * * * * * * *
44+
45+
FOSSIL_TEST(c_sanity_sys_execute) {
46+
const char *command = "echo Hello, Fossil!";
47+
int result = FOSSIL_SANITY_SYS_EXECUTE(command);
48+
49+
// Test cases
50+
ASSUME_ITS_EQUAL_I32(result, 0); // Assuming the command executes successfully
51+
} // end case
52+
53+
FOSSIL_TEST(c_sanity_sys_getpid) {
54+
int pid = FOSSIL_SANITY_SYS_GETPID();
55+
56+
// Test cases
57+
ASSUME_NOT_EQUAL_I32(pid, 0); // Process ID should not be 0
58+
} // end case
59+
60+
FOSSIL_TEST(c_sanity_sys_create_file) {
61+
const char *filename = "test_file.txt";
62+
int result = FOSSIL_SANITY_SYS_CREATE_FILE(filename);
63+
64+
// Test cases
65+
ASSUME_ITS_EQUAL_I32(result, 0); // File creation should succeed
66+
ASSUME_ITS_EQUAL_I32(FOSSIL_SANITY_SYS_FILE_EXISTS(filename), 1); // File should exist
67+
68+
// Cleanup
69+
remove(filename);
70+
} // end case
71+
72+
FOSSIL_TEST(c_sanity_sys_file_exists) {
73+
const char *filename = "test_file_exists.txt";
74+
75+
// Ensure file does not exist initially
76+
ASSUME_ITS_EQUAL_I32(FOSSIL_SANITY_SYS_FILE_EXISTS(filename), 0);
77+
78+
// Create the file
79+
FILE *file = fopen(filename, "w");
80+
ASSUME_NOT_CNULL(file);
81+
fclose(file);
82+
83+
// Test cases
84+
ASSUME_ITS_EQUAL_I32(FOSSIL_SANITY_SYS_FILE_EXISTS(filename), 1);
85+
86+
// Cleanup
87+
remove(filename);
88+
} // end case
89+
90+
91+
92+
// * * * * * * * * * * * * * * * * * * * * * * * *
93+
// * Fossil Logic Test Pool
94+
// * * * * * * * * * * * * * * * * * * * * * * * *
95+
FOSSIL_TEST_GROUP(c_sanity_test_cases) {
96+
FOSSIL_TEST_ADD(c_sanity_suite, c_sanity_sys_execute);
97+
FOSSIL_TEST_ADD(c_sanity_suite, c_sanity_sys_getpid);
98+
FOSSIL_TEST_ADD(c_sanity_suite, c_sanity_sys_create_file);
99+
FOSSIL_TEST_ADD(c_sanity_suite, c_sanity_sys_file_exists);
100+
101+
FOSSIL_TEST_REGISTER(c_sanity_suite);
102+
} // end of group

code/tests/cases/test_sanity.cpp

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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: 04/05/2014
11+
*
12+
* Copyright (C) 2014-2025 Fossil Logic. All rights reserved.
13+
* -----------------------------------------------------------------------------
14+
*/
15+
#include <fossil/pizza/framework.h>
16+
17+
// * * * * * * * * * * * * * * * * * * * * * * * *
18+
// * Fossil Logic Test Utilites
19+
// * * * * * * * * * * * * * * * * * * * * * * * *
20+
// Setup steps for things like test fixtures and
21+
// mock objects are set here.
22+
// * * * * * * * * * * * * * * * * * * * * * * * *
23+
24+
// Define the test suite and add test cases
25+
FOSSIL_SUITE(cpp_sanity_suite);
26+
27+
// Setup function for the test suite
28+
FOSSIL_SETUP(cpp_sanity_suite) {
29+
// Setup code here
30+
}
31+
32+
// Teardown function for the test suite
33+
FOSSIL_TEARDOWN(cpp_sanity_suite) {
34+
// Teardown code here
35+
}
36+
37+
// * * * * * * * * * * * * * * * * * * * * * * * *
38+
// * Fossil Logic Test Cases
39+
// * * * * * * * * * * * * * * * * * * * * * * * *
40+
// The test cases below are provided as samples, inspired
41+
// by the Meson build system's approach of using test cases
42+
// as samples for library usage.
43+
// * * * * * * * * * * * * * * * * * * * * * * * *
44+
45+
FOSSIL_TEST(cpp_sanity_sys_execute) {
46+
const char *command = "echo Hello, Fossil!";
47+
int result = FOSSIL_SANITY_SYS_EXECUTE(command);
48+
49+
// Test cases
50+
ASSUME_ITS_EQUAL_I32(result, 0); // Assuming the command executes successfully
51+
} // end case
52+
53+
FOSSIL_TEST(cpp_sanity_sys_getpid) {
54+
int pid = FOSSIL_SANITY_SYS_GETPID();
55+
56+
// Test cases
57+
ASSUME_NOT_EQUAL_I32(pid, 0); // Process ID should not be 0
58+
} // end case
59+
60+
FOSSIL_TEST(cpp_sanity_sys_create_file) {
61+
const char *filename = "test_file.txt";
62+
int result = FOSSIL_SANITY_SYS_CREATE_FILE(filename);
63+
64+
// Test cases
65+
ASSUME_ITS_EQUAL_I32(result, 0); // File creation should succeed
66+
ASSUME_ITS_EQUAL_I32(FOSSIL_SANITY_SYS_FILE_EXISTS(filename), 1); // File should exist
67+
68+
// Cleanup
69+
remove(filename);
70+
} // end case
71+
72+
FOSSIL_TEST(cpp_sanity_sys_file_exists) {
73+
const char *filename = "test_file_exists.txt";
74+
75+
// Ensure file does not exist initially
76+
ASSUME_ITS_EQUAL_I32(FOSSIL_SANITY_SYS_FILE_EXISTS(filename), 0);
77+
78+
// Create the file
79+
FILE *file = fopen(filename, "w");
80+
ASSUME_NOT_CNULL(file);
81+
fclose(file);
82+
83+
// Test cases
84+
ASSUME_ITS_EQUAL_I32(FOSSIL_SANITY_SYS_FILE_EXISTS(filename), 1);
85+
86+
// Cleanup
87+
remove(filename);
88+
} // end case
89+
90+
91+
92+
// * * * * * * * * * * * * * * * * * * * * * * * *
93+
// * Fossil Logic Test Pool
94+
// * * * * * * * * * * * * * * * * * * * * * * * *
95+
FOSSIL_TEST_GROUP(cpp_sanity_test_cases) {
96+
FOSSIL_TEST_ADD(cpp_sanity_suite, cpp_sanity_sys_execute);
97+
FOSSIL_TEST_ADD(cpp_sanity_suite, cpp_sanity_sys_getpid);
98+
FOSSIL_TEST_ADD(cpp_sanity_suite, cpp_sanity_sys_create_file);
99+
FOSSIL_TEST_ADD(cpp_sanity_suite, cpp_sanity_sys_file_exists);
100+
101+
FOSSIL_TEST_REGISTER(cpp_sanity_suite);
102+
} // end of group

code/tests/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ if get_option('with_test').enabled()
22
run_command(['python3', 'tools' / 'generate-runner.py'], check: true)
33

44
test_c = ['unit_runner.c']
5-
test_cases = ['sample', 'bdd', 'tdd', 'ddd', 'mark', 'mock']
5+
test_cases = ['sample', 'bdd', 'tdd', 'ddd', 'mark', 'mock', 'sanity']
66

77
foreach cases : test_cases
88
test_c += ['cases' / 'test_' + cases + '.c']

0 commit comments

Comments
 (0)