-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from andymccall/develop
enhancement(issue-16): setup unit testing framework
- Loading branch information
Showing
10 changed files
with
235 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,6 @@ obj | |
|
||
*.dat | ||
|
||
release | ||
release | ||
coverage | ||
test_runner* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "lib/unity"] | ||
path = lib/unity | ||
url = https://github.com/ThrowTheSwitch/Unity.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "../lib/unity/src/unity.h" // The Unity test framework | ||
#include "../src/constants.h" // Adjust the path as necessary | ||
#include "test_constants.h" | ||
|
||
void setUp(void) { | ||
// Set up code, if needed | ||
} | ||
|
||
void tearDown(void) { | ||
// Tear down code, if needed | ||
} | ||
|
||
void test_PROGRAM_NAME(void) { | ||
TEST_ASSERT_EQUAL_STRING("ez80op", PROGRAM_NAME); | ||
} | ||
|
||
void test_GIT_REPOSITORY(void) { | ||
TEST_ASSERT_EQUAL_STRING("https://github.com/andymccall/ez80op", GIT_REPOSITORY); | ||
} | ||
|
||
void test_GIT_INFO(void) { | ||
TEST_ASSERT_EQUAL_STRING("unknown", GIT_INFO); | ||
} | ||
|
||
void test_BUILD_YEAR(void) { | ||
TEST_ASSERT_EQUAL_STRING("2024", BUILD_YEAR); | ||
} | ||
|
||
void test_AUTHOR(void) { | ||
TEST_ASSERT_EQUAL_STRING("Andy McCall", AUTHOR); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef TEST_CONSTANTS_H | ||
#define TEST_CONSTANTS_H | ||
|
||
void setUp(void); | ||
void tearDown(void); | ||
void test_PROGRAM_NAME(void); | ||
void test_GIT_REPOSITORY(void); | ||
void test_GIT_INFO(void); | ||
void test_BUILD_YEAR(void); | ||
void test_AUTHOR(void); | ||
|
||
#endif // TEST_CONSTANTS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "test_constants.h" | ||
#include "test_opcode.h" | ||
|
||
int main(void) { | ||
UNITY_BEGIN(); | ||
RUN_TEST(test_createOpcode_should_ReturnValidOpcode); | ||
RUN_TEST(test_createOpcode_should_ReturnNullOnMallocFailure); | ||
RUN_TEST(test_PROGRAM_NAME); | ||
RUN_TEST(test_GIT_REPOSITORY); | ||
RUN_TEST(test_GIT_INFO); | ||
RUN_TEST(test_BUILD_YEAR); | ||
RUN_TEST(test_AUTHOR); | ||
return UNITY_END(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "../lib/unity/src/unity.h" // The Unity test framework | ||
#include "../src/opcode.h" // Adjust the path as necessary | ||
#include "test_opcode.h" | ||
|
||
void test_createOpcode_should_ReturnValidOpcode(void) { | ||
int number = 1; | ||
enum instructionType type = IO; // Replace with actual enum value | ||
char *name = "Test Opcode"; | ||
char *shortDescription = "Short Desc"; | ||
char *longDescription = "Long Desc"; | ||
ConditionBits conditionBits; | ||
|
||
conditionBits.S = true; | ||
conditionBits.S_explanation = strdup("Sign flag"); | ||
conditionBits.Z = false; | ||
conditionBits.Z_explanation = strdup("Zero flag"); | ||
conditionBits.H = true; | ||
conditionBits.H_explanation = strdup("Half carry flag"); | ||
conditionBits.PV = false; | ||
conditionBits.PV_explanation = strdup("Parity/Overflow flag"); | ||
conditionBits.N = true; | ||
conditionBits.N_explanation = strdup("Add/Subtract flag"); | ||
conditionBits.C = false; | ||
conditionBits.C_explanation = strdup("Carry flag"); | ||
|
||
opcode *code = createOpcode(number, type, name, shortDescription, longDescription, conditionBits); | ||
|
||
TEST_ASSERT_NOT_NULL(code); | ||
TEST_ASSERT_EQUAL_INT(number, code->number); | ||
TEST_ASSERT_EQUAL_INT(type, code->type); | ||
TEST_ASSERT_EQUAL_STRING(name, code->name); | ||
TEST_ASSERT_EQUAL_STRING(shortDescription, code->shortDescription); | ||
TEST_ASSERT_EQUAL_STRING(longDescription, code->longDescription); | ||
|
||
// Clean up | ||
free(code->name); | ||
free(code->shortDescription); | ||
free(code->longDescription); | ||
free(code); | ||
} | ||
|
||
void test_createOpcode_should_ReturnNullOnMallocFailure(void) { | ||
// // Simulate malloc failure by setting a limit on memory allocation | ||
// // This part is platform-specific and may require additional setup | ||
|
||
// // For demonstration purposes, we'll assume malloc fails | ||
// // You can use a custom malloc function to simulate this in a real test | ||
|
||
// // Example: | ||
// // set_malloc_limit(0); | ||
|
||
// opcode *code = createOpcode(1, IO, "Test", "Short", "Long", (ConditionBits) { // Create ConditionBits directly within the call | ||
// .S = true, | ||
// .S_explanation = "Sign flag is set if the result is negative", | ||
// .Z = true, | ||
// .Z_explanation = "Zero flag is set if the result is zero", | ||
// .H = false, | ||
// .H_explanation = NULL, | ||
// .PV = false, | ||
// .PV_explanation = NULL, | ||
// .N = true, | ||
// .N_explanation = "Negative flag is set if the result is negative", | ||
// .C = false, | ||
// .C_explanation = NULL | ||
// } ); | ||
|
||
// TEST_ASSERT_NULL(code); | ||
|
||
// // Reset malloc limit if necessary | ||
// // reset_malloc_limit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef TEST_OPCODE_H | ||
#define TEST_OPCODE_H | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "../lib/unity/src/unity.h" // The Unity test framework | ||
#include "../src/opcode.h" // Adjust the path as necessary | ||
|
||
void test_createOpcode_should_ReturnValidOpcode(void); | ||
void test_createOpcode_should_ReturnNullOnMallocFailure(void); | ||
|
||
#endif // TEST_OPCODE_H |