diff --git a/apps/calculation/test/calculation_store.cpp b/apps/calculation/test/calculation_store.cpp index 05633b529..15d3f0588 100644 --- a/apps/calculation/test/calculation_store.cpp +++ b/apps/calculation/test/calculation_store.cpp @@ -77,10 +77,12 @@ void assertCalculationDisplay(const char * input, ::Calculation::Calculation::Di quiz_assert(lastCalculation->exactAndApproximateDisplayedOutputsAreEqual(context) == sign); } if (exactOutput) { - quiz_assert(strcmp(lastCalculation->exactOutputText(), exactOutput) == 0); + constexpr int bufferSize = 500; + char buffer[bufferSize]; + quiz_assert(strcmpWithSystemParentheses(lastCalculation->exactOutputText(), exactOutput) == 0); } if (approximateOutput) { - quiz_assert(strcmp(lastCalculation->approximateOutputText(), approximateOutput) == 0); + quiz_assert(strcmpWithSystemParentheses(lastCalculation->approximateOutputText(), approximateOutput) == 0); } store->deleteAll(); } diff --git a/apps/solver/test/equation_store.cpp b/apps/solver/test/equation_store.cpp index 3452d6901..b33dda50e 100644 --- a/apps/solver/test/equation_store.cpp +++ b/apps/solver/test/equation_store.cpp @@ -40,16 +40,16 @@ void assert_equation_system_exact_solve_to(const char * equations[], EquationSto } if (type == EquationStore::Type::LinearSystem) { for (int i = 0; i < numberOfSolutions; i++) { - quiz_assert(strcmp(equationStore.variableAtIndex(i),variables[i]) == 0); + quiz_assert(strcmpWithSystemParentheses(equationStore.variableAtIndex(i),variables[i]) == 0); } } else { - quiz_assert(strcmp(equationStore.variableAtIndex(0), variables[0]) == 0); + quiz_assert(strcmpWithSystemParentheses(equationStore.variableAtIndex(0), variables[0]) == 0); } constexpr int bufferSize = 200; char buffer[bufferSize]; for (int i = 0; i < numberOfSolutions; i++) { equationStore.exactSolutionLayoutAtIndex(i, true).serializeForParsing(buffer, bufferSize); - quiz_assert(strcmp(buffer, solutions[i]) == 0); + quiz_assert(strcmpWithSystemParentheses(buffer, solutions[i]) == 0); } equationStore.removeAll(); } diff --git a/poincare/test/helper.cpp b/poincare/test/helper.cpp index fc3436671..9cb7fc05a 100644 --- a/poincare/test/helper.cpp +++ b/poincare/test/helper.cpp @@ -41,6 +41,28 @@ bool expressions_are_equal(Poincare::Expression expected, Poincare::Expression g return identical; } +bool isLeftParenthesisCodePoint(CodePoint c) { + return (c == UCodePointLeftSystemParenthesis) || (c == '('); +} + +bool isRightParenthesisCodePoint(CodePoint c) { + return (c == UCodePointRightSystemParenthesis) || (c == ')'); +} + +int strcmpWithSystemParentheses(const char * s1, const char * s2) { + quiz_assert(UTF8Decoder::CharSizeOfCodePoint(UCodePointLeftSystemParenthesis) == 1); + quiz_assert(UTF8Decoder::CharSizeOfCodePoint(UCodePointRightSystemParenthesis) == 1); + while(*s1 != 0 + && ((*s1 == *s2) + || (isLeftParenthesisCodePoint(*s1) && isLeftParenthesisCodePoint(*s2)) + || (isRightParenthesisCodePoint(*s1) && isRightParenthesisCodePoint(*s2)))) + { + s1++; + s2++; + } + return (*(unsigned char *)s1) - (*(unsigned char *)s2); +} + Expression parse_expression(const char * expression, bool canBeUnparsable) { quiz_print(expression); Expression result = Expression::Parse(expression); @@ -98,13 +120,14 @@ void assert_parsed_expression_process_to(const char * expression, const char * r print_expression(e, 0); #endif Expression m = process(e, globalContext, target, complexFormat, angleUnit); - char buffer[500]; - m.serialize(buffer, sizeof(buffer), DecimalMode, numberOfSignifiantDigits); + constexpr int bufferSize = 500; + char buffer[bufferSize]; + m.serialize(buffer, bufferSize, DecimalMode, numberOfSignifiantDigits); #if POINCARE_TESTS_PRINT_EXPRESSIONS cout << "---- serialize to: " << buffer << " ----" << endl; cout << "----- compared to: " << result << " ----\n" << endl; #endif - quiz_assert(strcmp(buffer, result) == 0); + quiz_assert(strcmpWithSystemParentheses(buffer, result) == 0); } template @@ -190,7 +213,7 @@ void assert_parsed_expression_layout_serialize_to_self(const char * expressionLa #if POINCARE_TESTS_PRINT_EXPRESSIONS cout << "---- serialized to: " << buffer << " ----\n" << endl; #endif - quiz_assert(strcmp(expressionLayout, buffer) == 0); + quiz_assert(strcmpWithSystemParentheses(expressionLayout, buffer) == 0); } void assert_expression_layouts_as(Poincare::Expression expression, Poincare::Layout layout) { @@ -207,7 +230,7 @@ void assert_expression_layout_serialize_to(Poincare::Layout layout, const char * cout << "---- serialized to: " << buffer << " ----" << endl; cout << "----- compared to: " << serialization << " ----\n" << endl; #endif - quiz_assert(strcmp(serialization, buffer) == 0); + quiz_assert(strcmpWithSystemParentheses(serialization, buffer) == 0); } template void assert_parsed_expression_evaluates_to(char const*, char const *, Poincare::ExpressionNode::ReductionTarget, Poincare::Preferences::AngleUnit, Poincare::Preferences::ComplexFormat, int); diff --git a/poincare/test/helper.h b/poincare/test/helper.h index 091d68d74..91d728ce0 100644 --- a/poincare/test/helper.h +++ b/poincare/test/helper.h @@ -18,6 +18,8 @@ constexpr Poincare::Preferences::ComplexFormat Real = Poincare::Preferences::Com constexpr Poincare::Preferences::PrintFloatMode DecimalMode = Poincare::Preferences::PrintFloatMode::Decimal; constexpr Poincare::Preferences::PrintFloatMode ScientificMode = Poincare::Preferences::PrintFloatMode::Scientific; +int strcmpWithSystemParentheses(const char * s1, const char * s2); + bool expressions_are_equal(Poincare::Expression expected, Poincare::Expression got); Poincare::Expression parse_expression(const char * expression, bool canBeUnparsable = false); Poincare::Expression parse_and_simplify(const char * expression);