diff --git a/xml_converter/attribute_test_script.sh b/xml_converter/attribute_test_script.sh
deleted file mode 100755
index d463524d..00000000
--- a/xml_converter/attribute_test_script.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/bash
-
-ATTRIBUTE_TEST_CASES_FOLDER_PATHS=("./test_cases/can_fade_tests")
-
-ATTRIBUTE_TEST_CASES=()
-
-for ATTRIBUTE_TEST_CASES_FOLDER_PATH in "${ATTRIBUTE_TEST_CASES_FOLDER_PATHS[@]}"; do
- if [ ! -d "$ATTRIBUTE_TEST_CASES_FOLDER_PATH" ]; then
- echo "Folder '$ATTRIBUTE_TEST_CASES_FOLDER_PATH' does not exist."
- exit 1
- fi
-
- attribute_name=$(basename "$ATTRIBUTE_TEST_CASES_FOLDER_PATH")
- TEST_OUTPUT_DIRECTORY="./test_cases/test_output/$attribute_name"
-
- if [ ! -d "$TEST_OUTPUT_DIRECTORY" ]; then
- mkdir "$TEST_OUTPUT_DIRECTORY"
- fi
-
- while IFS= read -r -d $'\0' file; do
- ATTRIBUTE_TEST_CASES+=("$file")
- done < <(find "$ATTRIBUTE_TEST_CASES_FOLDER_PATH" -type f -print0)
-
- for test_case in "${ATTRIBUTE_TEST_CASES[@]}"; do
- file_name=$(basename "$test_case")
- ./build/xml_converter --input-taco-path "$test_case" --output-taco-path "$TEST_OUTPUT_DIRECTORY/$file_name" 1> /dev/null
- done
-done
-
-./build/xml_converter_tests
diff --git a/xml_converter/test_cases/can_fade_tests/can_fade_is_false.xml b/xml_converter/test_cases/can_fade_tests/can_fade_is_correct.xml
similarity index 100%
rename from xml_converter/test_cases/can_fade_tests/can_fade_is_false.xml
rename to xml_converter/test_cases/can_fade_tests/can_fade_is_correct.xml
diff --git a/xml_converter/test_cases/can_fade_tests/can_fade_is_zero.xml b/xml_converter/test_cases/can_fade_tests/can_fade_is_different_file.xml
similarity index 100%
rename from xml_converter/test_cases/can_fade_tests/can_fade_is_zero.xml
rename to xml_converter/test_cases/can_fade_tests/can_fade_is_different_file.xml
diff --git a/xml_converter/test_cases/can_fade_tests/can_fade_is_wrong_output.xml b/xml_converter/test_cases/can_fade_tests/can_fade_is_wrong_output.xml
new file mode 100644
index 00000000..180562d2
--- /dev/null
+++ b/xml_converter/test_cases/can_fade_tests/can_fade_is_wrong_output.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/xml_converter/tests/attribute_testing.py b/xml_converter/tests/attribute_testing.py
new file mode 100755
index 00000000..8b6a90ad
--- /dev/null
+++ b/xml_converter/tests/attribute_testing.py
@@ -0,0 +1,140 @@
+from dataclasses import dataclass
+import subprocess
+import re
+import os
+from typing import Dict, List
+
+# Path to compiled C++ executable
+xml_converter: str = "../build/xml_converter"
+
+
+@dataclass
+class Attribute_Tests:
+ attribute_name: str
+ attribute_path: str
+ tests: List[str]
+ output_result: Dict[str, List[str]]
+ expect_output_to_be_equal: Dict[str, bool]
+ expect_files_to_be_equal: Dict[str, bool]
+
+
+def run_xml_converter(*args):
+ try:
+ # Build the command to execute the C++ program with the desired function and arguments
+ cmd = [xml_converter] + list(args)
+
+ # Run the C++ program and capture its output
+ result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
+
+ # Check if the C++ program executed successfully
+ if result.returncode == 0:
+ return result.stdout
+ else:
+ return result.stderr
+ except Exception as e:
+ print("Error:", e)
+ return None
+
+
+def are_files_equal(file_path1, file_path2) -> bool:
+ try:
+ with open(file_path1, 'rb') as file1, open(file_path2, 'rb') as file2:
+ content1 = file1.read()
+ content2 = file2.read()
+
+ return content1 == content2
+
+ except (FileNotFoundError, PermissionError):
+ print(f"Error opening file {file_path1} or {file_path2}")
+ return False
+
+
+def are_arrays_equal(array1, array2) -> bool:
+ if len(array1) != len(array2):
+ return False
+
+ for i in range(len(array1)):
+ if array1[i] != array2[i]:
+ return False
+
+ return True
+
+
+arg_input_xml: str = "--input-taco-path"
+arg_output_xml: str = "--output-taco-path"
+
+chrono_patterns = [
+ "The taco parse function took [0-9]+ milliseconds to run",
+ "The xml write function took [0-9]+ milliseconds to run",
+ "The protobuf write function took [0-9]+ milliseconds to run"
+]
+
+
+if __name__ == "__main__":
+ # TODO: This will need to be extracted as more attributes and tests are added
+ attribute: Attribute_Tests = Attribute_Tests(
+ attribute_name="can_fade",
+ attribute_path="../test_cases/can_fade_tests",
+ tests=["_is_correct", "_is_different_file", "_is_wrong_output"],
+ output_result={
+ "_is_correct": ['Loading taco pack ../test_cases/can_fade_tests/can_fade_is_correct.xml'],
+ "_is_different_file": ['Loading taco pack ../test_cases/can_fade_tests/can_fade_is_different_file.xml'],
+ "_is_wrong_output": ['WRONG']
+ },
+ expect_output_to_be_equal={
+ "_is_correct": True,
+ "_is_different_file": True,
+ "_is_wrong_output": False,
+ },
+ expect_files_to_be_equal={
+ "_is_correct": True,
+ "_is_different_file": False,
+ "_is_wrong_output": True,
+ }
+ )
+
+ # Ensure that the test output directory is created
+ if not os.path.exists(attribute.attribute_path + "-output/"):
+ try:
+ os.makedirs(attribute.attribute_path + "-output/")
+ except OSError as e:
+ print(f"Error: {e}")
+
+ for test in attribute.tests:
+ arg1 = attribute.attribute_path + "/" + attribute.attribute_name + test + ".xml"
+ arg2 = attribute.attribute_path + "-output/" + attribute.attribute_name + test + ".xml"
+
+ result = run_xml_converter(arg_input_xml, arg1, arg_output_xml, arg2)
+ if result is not None:
+ # Remove lines about how long it took to run
+ split_result = result.split("\n")
+ filtered_array = []
+ for line in split_result:
+ match_found = False
+ for pattern in chrono_patterns:
+ if re.search(pattern, line) or line == "":
+ match_found = True
+ break
+ if not match_found:
+ filtered_array.append(line)
+
+ output_test: bool = True
+ file_test: bool = True
+
+ if are_arrays_equal(filtered_array, attribute.output_result[test]) != attribute.expect_output_to_be_equal[test]:
+ print(f"Output did not match for test {attribute.attribute_name}{test}")
+ print(f"Expected {attribute.output_result[test]} and got {filtered_array}")
+ output_test = False
+
+ if are_files_equal(arg1, arg2) != attribute.expect_files_to_be_equal[test]:
+ print(f"Files were incorrect for test {attribute.attribute_name}{test}")
+ print(f"Expected {attribute.expect_files_to_be_equal[test]}")
+ print(f"arg1: {arg1}")
+ print(f"arg2: {arg2}")
+ file_test = False
+
+ if output_test and file_test:
+ print(f"Successful test {attribute.attribute_name}{test}")
+
+ else:
+ print(f"Failed to execute {attribute.attribute_name}{test}")
diff --git a/xml_converter/tests/test_bool.cpp b/xml_converter/tests/test_bool.cpp
deleted file mode 100644
index 58d56003..00000000
--- a/xml_converter/tests/test_bool.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-#include
-#include
-
-class BoolTest : public ::testing::Test {
- protected:
- void SetUp() override {
- }
- void TearDown() override {
- }
-};
-
-bool compare_files(const std::string& file1_path, const std::string& file2_path) {
- std::ifstream file1(file1_path);
- std::ifstream file2(file2_path);
-
- if (!file1.is_open() || !file2.is_open()) {
- std::cerr << "Error: Could not open one or both of the files." << std::endl;
- return false;
- }
-
- char char1, char2;
- bool files_are_equal = true;
-
- while (true) {
- char1 = file1.get();
- char2 = file2.get();
-
- if (char1 != char2) {
- files_are_equal = false;
- break;
- }
-
- if (file1.eof() && file2.eof()) {
- break; // Reached the end of both files
- }
-
- // If one file reaches the end before the other, they are not equal
- if (file1.eof() || file2.eof()) {
- files_are_equal = false;
- break;
- }
- }
-
- file1.close();
- file2.close();
-
- return files_are_equal;
-}
-
-TEST_F(BoolTest, ValueIsFalse) {
- std::string xml_input = "./test_cases/can_fade_tests/can_fade_is_false.xml";
- std::string xml_output = "./test_cases/test_output/can_fade_tests/can_fade_is_false.xml";
- EXPECT_TRUE(compare_files(xml_input, xml_output));
-}
-
-TEST_F(BoolTest, ValueIsZero) {
- std::string xml_input = "./test_cases/can_fade_tests/can_fade_is_zero.xml";
- std::string xml_output = "./test_cases/test_output/can_fade_tests/can_fade_is_zero.xml";
- EXPECT_FALSE(compare_files(xml_input, xml_output));
-}