4242#include < libxml/tree.h>
4343
4444#include < string>
45+ #include < list>
46+
47+ #include < stdlib.h>
4548
4649using std::string;
50+ using std::list;
4751using Bytes = std::vector<uint8_t >;
4852
4953namespace parameterFramework
@@ -156,11 +160,21 @@ struct AllParamsPF : public ParameterFramework
156160 if (result != expected) {
157161 utility::TmpFile resultFile (result);
158162 utility::TmpFile expectedFile (expected);
159- auto gitCommand = " git --no-pager diff --word-diff-regex='[^ <>]+' --color --no-index " ;
160- auto diffSuccess =
161- system ((gitCommand + resultFile.getPath () + ' ' + expectedFile.getPath ()).c_str ());
162- if (diffSuccess != 0 ) {
163- WARN (" Failed to pretty-print the difference between actual and expected results." );
163+ string command = " git --no-pager diff --word-diff-regex='[^ <>]+'"
164+ " --color --no-index --exit-code " +
165+ resultFile.getPath () + ' ' + expectedFile.getPath ();
166+
167+ // `system` return -1 or 127 on failure, the command error code otherwise
168+ // `git diff` return 1 if the files are the different (thanks to --exit-code)
169+ auto status = system (command.c_str ());
170+ #ifdef WIFEXITED // Posix platform
171+ bool success = WIFEXITED (status) and WEXITSTATUS (status) == 1 ;
172+ #else
173+ bool success = status == 1 ;
174+ #endif
175+ if (not success) {
176+ WARN (" Warning: Failed to pretty-print the difference between "
177+ " actual and expected results with `git diff'" );
164178 }
165179 }
166180 }
@@ -363,6 +377,24 @@ static const char *testBasicSettingsXML = R"(
363377 <BitParameter Name="thirty_two">4294967295</BitParameter>
364378 </BitParameterBlock>
365379)" ;
380+ static const char *testRawHexBasicSettingsXML = R"(
381+ <BooleanParameter Name="bool">0x1</BooleanParameter>
382+ <BooleanParameter Name="bool_array">0x0 0x1</BooleanParameter>
383+ <IntegerParameter Name="integer">0x0064</IntegerParameter>
384+ <IntegerParameter Name="integer_array">0xFFFFFFF6 0x00000000 0x00000008 0x0000000A</IntegerParameter>
385+ <FixedPointParameter ValueSpace="Raw" Name="fix_point">0x24000000</FixedPointParameter>
386+ <FixedPointParameter ValueSpace="Raw" Name="fix_point_array">0x72000000 0x0B000000 0xF0000000</FixedPointParameter>
387+ <EnumParameter Name="enum">five</EnumParameter>
388+ <EnumParameter Name="enum_array">eight min eight min</EnumParameter>
389+ <StringParameter Name="string">A string of 32 character.@@@@@@@</StringParameter>
390+ <BitParameterBlock Name="bit_block">
391+ <BitParameter Name="one">0x1</BitParameter>
392+ <BitParameter Name="two">0x2</BitParameter>
393+ <BitParameter Name="six">0xA</BitParameter>
394+ <BitParameter Name="sixteen">0x48</BitParameter>
395+ <BitParameter Name="thirty_two">0xFFFFFFFF</BitParameter>
396+ </BitParameterBlock>
397+ )" ;
366398
367399SCENARIO_METHOD (SettingsTestPF, " Export and import XML settings" , " [handler][settings][xml]" )
368400{
@@ -377,12 +409,26 @@ SCENARIO_METHOD(SettingsTestPF, "Export and import XML settings", "[handler][set
377409 checkXMLEq (basicParams.getAsXML (),
378410 mkBasicSettings (defaultBasicSettingsXML, " parameter_block" ));
379411 }
380- WHEN (" Importing basic parameter XML" ) {
381- string testSettings = mkBasicSettings (testBasicSettingsXML, " parameter_block" );
382- CHECK_NOTHROW (basicParams.setAsXML (testSettings));
412+ string testSettings = mkBasicSettings (testBasicSettingsXML, " parameter_block" );
413+ string rawTestSettings = mkBasicSettings (testRawHexBasicSettingsXML, " parameter_block" );
414+
415+ auto checkExport = [&] {
383416 THEN (" Exported settings should be the ones imported" ) {
384417 checkXMLEq (basicParams.getAsXML (), testSettings);
385418 }
419+ THEN (" Exported raw settings should be the ones imported" ) {
420+ setRawValueSpace (true );
421+ setHexOutputFormat (true );
422+ checkXMLEq (basicParams.getAsXML (), rawTestSettings);
423+ }
424+ };
425+ WHEN (" Importing basic parameter XML" ) {
426+ CHECK_NOTHROW (basicParams.setAsXML (testSettings));
427+ checkExport ();
428+ }
429+ WHEN (" Importing raw basic parameter XML" ) {
430+ CHECK_NOTHROW (basicParams.setAsXML (rawTestSettings));
431+ checkExport ();
386432 }
387433}
388434
@@ -497,4 +543,63 @@ SCENARIO_METHOD(SettingsTestPF, "Import basic params in one format, export in an
497543 }
498544}
499545
546+ struct MappingPF : public ParameterFramework
547+ {
548+ MappingPF () : ParameterFramework{getConfig ()} { REQUIRE_NOTHROW (start ()); }
549+
550+ Config getConfig ()
551+ {
552+ Config config;
553+ config.instances = " <BooleanParameter Name='bool' Mapping='bool_map'>" ;
554+ config.subsystemMapping = " subsystem_mapping" ;
555+ return config;
556+ }
557+ };
558+
559+ SCENARIO (" Mapping handle access" , " [handler][mapping]" )
560+ {
561+ GIVEN (" A PF with mappings" ) {
562+ Config config;
563+ config.subsystemMapping = " rootK:rootV" ;
564+ config.components = " <ComponentType Name='componentType' Mapping='typeK:typeV' />" ;
565+ config.instances = " <BooleanParameter Name='param' Mapping='paramK:paramV' />"
566+ " <Component Name='component' Mapping='instanceK:instanceV' "
567+ " Type='componentType' />" ;
568+ ParameterFramework pf{config};
569+ REQUIRE_NOTHROW (pf.start ());
570+
571+ struct TestVector
572+ {
573+ string path;
574+ list<string> valid;
575+ list<string> invalid;
576+ };
577+ list<TestVector> testVectors = {
578+ // clang-format off
579+ {" /test/test" , {" root" }, {" param" , " type" , " instance" }},
580+ {" /test/test/param" , {" root" , " param" }, {" type" , " instance" }},
581+ {" /test/test/component" , {" root" , " type" , " instance" }, {" param" }}
582+ // clang-format on
583+ };
584+
585+ for (auto &test : testVectors) {
586+ GIVEN (" An element handle of " + test.path ) {
587+ ElementHandle handle (pf, test.path );
588+
589+ for (auto &valid : test.valid ) {
590+ THEN (" The following mapping should exist: " + valid) {
591+ CHECK (handle.getMappingData (valid + " K" ) == valid + " V" );
592+ }
593+ }
594+
595+ for (auto &invalid : test.invalid ) {
596+ THEN (" The following mapping should not exist: " + invalid) {
597+ CHECK_THROWS_AS (handle.getMappingData (invalid + " K" ), Exception);
598+ }
599+ }
600+ }
601+ }
602+ }
603+ }
604+
500605} // namespace parameterFramework
0 commit comments