Hoyt's FORK of DemoIccMAX 2.1.17.hoyt
Documentation for Hoyt's FORK of DemoIccMAX
Loading...
Searching...
No Matches
TestCIccTagXmlProfileSequenceId.cpp
Go to the documentation of this file.
1/**
2 * @file TestCIccTagXmlProfileSequenceId.cpp
3 * @brief Unit tests for CIccTagXmlProfileSequenceId()
4 * @author @h02332 | David Hoyt | @xsscx
5 * @date 29 MAY 2024
6 * @version 1.0.5
7 *
8 * This unit test is designed to verify the parsing functionality of the
9 * CIccTagXmlProfileSequenceId class from the IccLibXML library. It uses libxml2 to
10 * create a sample XML document and tests how the CIccTagXmlProfileSequenceId class
11 * processes this input. The test checks for both correct and incorrect scenarios.
12 *
13 * Expected Outcomes:
14 * - When provided with a properly structured XML document, the ParseXml method
15 * should return true, indicating successful parsing and validation of the XML content.
16 * - If the XML structure is incorrect or critical elements are missing, the method
17 * should return false, indicating a failure to correctly parse the XML.
18 *
19 * Compile:
20 * clang++ -std=c++11 -g -fsanitize=address,undefined -fno-omit-frame-pointer \
21 * -o TestCIccTagXmlProfileSequenceId TestCIccTagXmlProfileSequenceId.cpp \
22 * -I/usr/local/include \
23 * -I/IccProfLib \
24 * -I/IccXML/IccLibXML \
25 * -L/Build/IccProfLib \
26 * -L/Build/IccXML \
27 * -L/usr/local/Cellar/libxml2/2.12.6/lib/ \
28 * -lIccProfLib2 -lIccXML2 -lpthread -lxml2
29 *
30 * Usage:
31 * Compile and run this file to perform the tests. The console output will display
32 * the test results, showing whether each scenario passed or failed.
33 *
34 * Comment: If you run this Code and think you've found a new, unique and distinct Bug...
35 * Please Submit a PR to increase improve the CIccTagXmlProfileSequenceId() Unit Test.
36 *
37 * This program is free software: you can redistribute it and/or modify
38 * it under the terms of the GNU General Public License as published by
39 * the Free Software Foundation, either version 3 of the License, or
40 * (at your option) any later version.
41 *
42 * This program is distributed in the hope that it will be useful,
43 * but WITHOUT ANY WARRANTY; without even the implied warranty of
44 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 * GNU General Public License for more details.
46 *
47 * You should have received a copy of the GNU General Public License
48 * along with this program. If not, see <http://www.gnu.org/licenses/>.
49 *
50 */
51
52#pragma mark - Headers
53
54/**
55@brief Core and external libraries necessary for the fuzzer functionality.
56
57@details This section includes the necessary headers for the XML parsing library (libxml), the standard I/O stream
58library, and a custom header for the CIccTagXmlProfileSequenceId class. These libraries are essential for handling XML
59documents, performing standard input/output operations, and utilizing the custom functionality of the CIccTagXmlProfileSequenceId class.
60*/
61#include <libxml/parser.h> // Includes libxml parser functions for XML parsing
62#include <libxml/tree.h> // Includes libxml tree functions for XML document handling
63#include "IccTagXml.h" // Includes custom header file for CIccTagXmlProfileSequenceId class definition
64#include <iostream> // Includes standard I/O stream library for console output
65#include <string> // Includes standard string library
66
67#pragma mark - Main Entry
68
69/**
70@brief Main function to initiate unit tests for the CIccTagXmlProfileSequenceId class.
71
72@details This function initializes the libxml library, creates a new XML document with a root node and a child node, and
73tests the ParseXml method of the CIccTagXmlProfileSequenceId class. The test result is output to the console. Finally,
74the function cleans up the XML document and the libxml parser to prevent memory leaks.
75
76@return int - Returns 0 upon successful completion.
77*/
78int main() {
79 std::cout << "Starting unit tests for CIccTagXmlProfileSequenceId...\n";
80
81 // Initialize libxml library
82 xmlInitParser();
83
84 // Create a new XML document
85 xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); // Create a new XML document with version 1.0
86 xmlNodePtr rootNode = xmlNewNode(nullptr, BAD_CAST "ProfileSequenceId"); // Create the root node named "ProfileSequenceId"
87 xmlDocSetRootElement(doc, rootNode); // Set the root node as the document's root element
88
89 // Create a child node named "ProfileIdDesc" with an attribute
90 xmlNodePtr profileNode = xmlNewChild(rootNode, nullptr, BAD_CAST "ProfileIdDesc", nullptr); // Create a child node under root node
91 xmlNewProp(profileNode, BAD_CAST "id", BAD_CAST "12345"); // Add an attribute "id" with value "12345" to the child node
92
93 // Create a CIccTagXmlProfileSequenceId object
95 std::string parseStr;
96
97 // Test the parsing function
98 bool parseResult = tag.ParseXml(rootNode, parseStr); // Call the ParseXml method on the tag object with rootNode
99
100 // Define the test results based on the parseResult
101 if (!parseResult) {
102 std::cout << "Test failed: ParseXml should not return false when a proper node is provided.\n"; // Output failure message if parsing fails
103 } else {
104 std::cout << "Test succeeded: ParseXml correctly handled the provided node.\n"; // Output success message if parsing succeeds
105 }
106
107 // Cleanup
108 xmlFreeDoc(doc); // Free the document to prevent memory leaks
109 xmlCleanupParser(); // Cleanup the libxml parser
110
111 return 0; // Return success
112}
File: IccTagXml.h.
int main()
Core and external libraries necessary for the fuzzer functionality.
virtual bool ParseXml(xmlNode *pNode, std::string &parseStr)