return FinalNameValue;
+}
+
+bool HexToInt(std::string *HexString, int *Number){
+
+ // Check that each character in the string is a number
+ // or a letter (a-f/A-F).
+
+ char Char = 0;
+ int CharNum = 0;
+
+ for (int CharSeek = 0;
+ CharSeek < HexString->size(); CharSeek++){
+
+ // Check if character is a number (0-9).
+
+ Char = HexString->at(CharSeek);
+ CharNum = Char;
+
+ if (CharNum >= 48 &&
+ CharNum <= 57){
+
+ continue;
+
+ }
+
+ // Check if character is a letter (A-F)
+
+ if (CharNum >= 65 &&
+ CharNum <= 70){
+
+ continue;
+
+ }
+
+ // Check if character is a letter (a-f).
+
+ if (CharNum >= 97 &&
+ CharNum <= 102){
+
+ continue;
+
+ }
+
+ // Exit from subroutine as character is invalid.
+
+ return false;
+
+ }
+
+ // Convert a Hex value that is in string to integer.
+
+ try {
+
+ *Number = stoi((*HexString), nullptr, 16);
+
+ }
+
+ catch (const std::invalid_argument &err){
+
+ return false;
+
+ }
+
+ catch (const std::out_of_range &err){
+
+ return false;
+
+ }
+
+ return true;
+
}
\ No newline at end of file
ASSERT_EQ(PropertyName, "TEST");
ASSERT_EQ(PropertyValue, "OK");
+}
+
+TEST(CommonFunctions, HexToInt){
+
+ string Value1 = "10"; // 16
+ string Value2 = "50"; // 80
+ string Value3 = "4F"; // 79
+ string Value4 = "FF"; // 255
+ string Value5 = "FFF"; // 4095
+ string Value6 = "FFFF"; // 65535
+ string Value7 = "75AB"; // 30123
+ string Value8 = "2AC"; // 684
+ string Value9 = "!"; // Fail
+ string Value10 = "4BZ"; // Fail
+ string Value11 = "Z?!$"; // Fail
+
+ int OutputValue = 0;
+ bool Result = false;
+
+ Result = HexToInt(&Value1, &OutputValue);
+
+ ASSERT_EQ(Result, true);
+ ASSERT_EQ(OutputValue, 16);
+
+ Result = HexToInt(&Value2, &OutputValue);
+ ASSERT_EQ(Result, true);
+ ASSERT_EQ(OutputValue, 80);
+
+ Result = HexToInt(&Value3, &OutputValue);
+ ASSERT_EQ(Result, true);
+ ASSERT_EQ(OutputValue, 79);
+
+ Result = HexToInt(&Value4, &OutputValue);
+ ASSERT_EQ(Result, true);
+ ASSERT_EQ(OutputValue, 255);
+
+ Result = HexToInt(&Value5, &OutputValue);
+ ASSERT_EQ(Result, true);
+ ASSERT_EQ(OutputValue, 4095);
+
+ Result = HexToInt(&Value6, &OutputValue);
+ ASSERT_EQ(Result, true);
+ ASSERT_EQ(OutputValue, 65535);
+
+ Result = HexToInt(&Value7, &OutputValue);
+ ASSERT_EQ(Result, true);
+ ASSERT_EQ(OutputValue, 30123);
+
+ Result = HexToInt(&Value8, &OutputValue);
+ ASSERT_EQ(Result, true);
+ ASSERT_EQ(OutputValue, 684);
+
+ Result = HexToInt(&Value9, &OutputValue);
+ ASSERT_EQ(Result, false);
+
+ Result = HexToInt(&Value10, &OutputValue);
+ ASSERT_EQ(Result, false);
+
+ Result = HexToInt(&Value11, &OutputValue);
+ ASSERT_EQ(Result, false);
+
}
\ No newline at end of file