A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
DlgIOTester.h
Go to the documentation of this file.
1// Copyright Csaba Molnar, Daniel Butum. All Rights Reserved.
2#pragma once
3
4#include "CoreTypes.h"
5#include "Logging/LogMacros.h"
6
7#include "DlgIOTesterTypes.h"
8
10
11
16class DLGSYSTEM_API FDlgIOTester
17{
18public:
19 // Tests Parser and Writer
20 template <typename ConfigWriterType, typename ConfigParserType>
21 static bool TestParser(const FDlgIOTesterOptions& Options, const FString NameWriterType = FString(),
22 const FString NameParserType = FString());
23
24 // Test all parsers/writers
25 static bool TestAllParsers();
26
27 template <typename ConfigWriterType, typename ConfigParserType, typename StructType>
28 static bool TestStruct(const FString& StructDescription,
29 const FDlgIOTesterOptions& Options,
30 const FString NameWriterType = FString(),
31 const FString NameParserType = FString());
32};
33
34
35template <typename ConfigWriterType, typename ConfigParserType>
36bool FDlgIOTester::TestParser(const FDlgIOTesterOptions& Options, const FString NameWriterType, const FString NameParserType)
37{
38 bool bAllSucceeded = true;
39
40 bAllSucceeded &= TestStruct<ConfigWriterType, ConfigParserType, FDlgTestStructPrimitives>("Struct of Primitives", Options, NameWriterType, NameParserType);
41 bAllSucceeded &= TestStruct<ConfigWriterType, ConfigParserType, FDlgTestStructComplex>("Struct of Complex types", Options, NameWriterType, NameParserType);
42
43 bAllSucceeded &= TestStruct<ConfigWriterType, ConfigParserType, FDlgTestArrayPrimitive>("Array of Primitives", Options, NameWriterType, NameParserType);
44 bAllSucceeded &= TestStruct<ConfigWriterType, ConfigParserType, FDlgTestArrayComplex>("Array of Complex types", Options, NameWriterType, NameParserType);
45
46 bAllSucceeded &= TestStruct<ConfigWriterType, ConfigParserType, FDlgTestSetPrimitive>("Set of Primitives", Options, NameWriterType, NameParserType);
47 bAllSucceeded &= TestStruct<ConfigWriterType, ConfigParserType, FDlgTestSetComplex>("Set of Complex types", Options, NameWriterType, NameParserType);
48
49 bAllSucceeded &= TestStruct<ConfigWriterType, ConfigParserType, FDlgTestMapPrimitive>("Map with Primitives", Options, NameWriterType, NameParserType);
50 bAllSucceeded &= TestStruct<ConfigWriterType, ConfigParserType, FDlgTestMapComplex>("Map with Complex types", Options, NameWriterType, NameParserType);
51
52 return bAllSucceeded;
53}
54
55
56template <typename ConfigWriterType, typename ConfigParserType, typename StructType>
57bool FDlgIOTester::TestStruct(const FString& StructDescription, const FDlgIOTesterOptions& Options, const FString NameWriterType, const FString NameParserType)
58{
59 StructType ExportedStruct;
60 StructType ImportedStruct;
61 ExportedStruct.GenerateRandomData(Options);
62 ImportedStruct.GenerateRandomData(Options);
63
64 // Write struct
65 ConfigWriterType Writer;
66 //Writer.SetLogVerbose(true);
67 Writer.Write(StructType::StaticStruct(), &ExportedStruct);
68 const FString WriterString = Writer.GetAsString();
69
70 // Read struct
71 ConfigParserType Parser;
72 //Parser.SetLogVerbose(true);
73 Parser.InitializeParserFromString(WriterString);
74 Parser.ReadAllProperty(StructType::StaticStruct(), &ImportedStruct);
75
76 // Should be the same
77 FString ErrorMessage;
78 if (ExportedStruct.IsEqual(ImportedStruct, ErrorMessage))
79 {
80 return true;
81 }
82
83 if (NameWriterType.IsEmpty() || NameParserType.IsEmpty())
84 {
85 UE_LOG(LogDlgIOTester, Warning, TEXT("TestStruct: Test Failed (both empty) = %s"), *StructDescription);
86 }
87 else
88 {
89 // Used only for debugging
90 ConfigWriterType DebugParser;
91 DebugParser.Write(StructType::StaticStruct(), &ImportedStruct);
92 const FString ParserString = DebugParser.GetAsString();
93
94 UE_LOG(LogDlgIOTester, Warning, TEXT("This = ExportedStruct, Other = ImportedStruct"));
95 UE_LOG(LogDlgIOTester, Warning, TEXT("Writer = %s, Parser = %s. Test Failed = %s"), *NameWriterType, *NameParserType, *StructDescription);
96 UE_LOG(LogDlgIOTester, Warning, TEXT("ErrorMessage = %s"), *ErrorMessage);
97 UE_LOG(LogDlgIOTester, Warning, TEXT("ExportedStruct.GetAsString() = |%s|\n"), *WriterString);
98 UE_LOG(LogDlgIOTester, Warning, TEXT("ImportedStruct.GetAsString() = |%s|\n"), *ParserString);
99 UE_LOG(LogDlgIOTester, Warning, TEXT(""));
100 }
101
102 return false;
103}
DECLARE_LOG_CATEGORY_EXTERN(LogDlgIOTester, All, All)
static bool TestStruct(const FString &StructDescription, const FDlgIOTesterOptions &Options, const FString NameWriterType=FString(), const FString NameParserType=FString())
Definition DlgIOTester.h:57
static bool TestParser(const FDlgIOTesterOptions &Options, const FString NameWriterType=FString(), const FString NameParserType=FString())
Definition DlgIOTester.h:36