Message ID | 20220816015414.7462-4-laurent.pinchart@ideasonboard.com |
---|---|
State | Accepted |
Headers | show |
Series |
|
Related | show |
Hi Laurent, On Tue, Aug 16, 2022 at 04:54:08AM +0300, Laurent Pinchart via libcamera-devel wrote: > Add 16-bit integer parsing tests, including a test to verify the > out-of-range checks when parsing 32-bit integers as 16-bit values. That I can't find the test for the out-of-range checks...? Or is it not added because it fails? Paul > test currently fails. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > --- > test/yaml-parser.cpp | 77 ++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 68 insertions(+), 9 deletions(-) > > diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp > index 803e70beb782..28f8cc8822b3 100644 > --- a/test/yaml-parser.cpp > +++ b/test/yaml-parser.cpp > @@ -24,8 +24,10 @@ using namespace std; > static const string testYaml = > "string: libcamera\n" > "double: 3.14159\n" > - "uint32_t: 100\n" > - "int32_t: -100\n" > + "int16_t: -1000\n" > + "uint16_t: 1000\n" > + "int32_t: -100000\n" > + "uint32_t: 100000\n" > "size: [1920, 1080]\n" > "list:\n" > " - James\n" > @@ -74,6 +76,8 @@ protected: > > enum class Type { > String, > + Int16, > + UInt16, > Int32, > UInt32, > Double, > @@ -86,8 +90,10 @@ protected: > { > bool isList = type == Type::List || type == Type::Size; > bool isScalar = !isList && type != Type::Dictionary; > - bool isInteger = type == Type::Int32 || type == Type::UInt32; > - bool isSigned = type == Type::Int32; > + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; > + bool isInteger32 = type == Type::Int32 || type == Type::UInt32; > + bool isInteger = isInteger16 || isInteger32; > + bool isSigned = type == Type::Int16 || type == Type::Int32; > > if ((isScalar && !obj.isValue()) || (!isScalar && obj.isValue())) { > std::cerr > @@ -118,6 +124,20 @@ protected: > return TestFail; > } > > + if (!isInteger16 && obj.get<int16_t>()) { > + std::cerr > + << "Object " << name << " didn't fail to parse as " > + << "int16_t" << std::endl; > + return TestFail; > + } > + > + if ((!isInteger16 || isSigned) && obj.get<uint16_t>()) { > + std::cerr > + << "Object " << name << " didn't fail to parse as " > + << "uint16_t" << std::endl; > + return TestFail; > + } > + > if (!isInteger && obj.get<int32_t>()) { > std::cerr > << "Object " << name << " didn't fail to parse as " > @@ -154,7 +174,8 @@ protected: > { > uint64_t unsignedValue = static_cast<uint64_t>(value); > std::string strValue = std::to_string(value); > - bool isSigned = type == Type::Int32; > + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; > + bool isSigned = type == Type::Int16 || type == Type::Int32; > > /* All integers can be parsed as strings or double. */ > > @@ -174,6 +195,26 @@ protected: > return TestFail; > } > > + if (isInteger16) { > + if (obj.get<int16_t>().value_or(0) != value || > + obj.get<int16_t>(0) != value) { > + std::cerr > + << "Object " << name << " failed to parse as " > + << "int16_t" << std::endl; > + return TestFail; > + } > + } > + > + if (isInteger16 && !isSigned) { > + if (obj.get<uint16_t>().value_or(0) != unsignedValue || > + obj.get<uint16_t>(0) != unsignedValue) { > + std::cerr > + << "Object " << name << " failed to parse as " > + << "uint16_t" << std::endl; > + return TestFail; > + } > + } > + > if (obj.get<int32_t>().value_or(0) != value || > obj.get<int32_t>(0) != value) { > std::cerr > @@ -231,8 +272,8 @@ protected: > } > > std::vector<const char *> rootElemNames = { > - "string", "double", "int32_t", "uint32_t", "size", > - "list", "dictionary", "level1", > + "string", "double", "int16_t", "uint16_t", "int32_t", > + "uint32_t", "size", "list", "dictionary", "level1", > }; > > for (const char *name : rootElemNames) { > @@ -255,13 +296,31 @@ protected: > return TestFail; > } > > + /* Test int16_t object */ > + auto &int16Obj = (*root)["int16_t"]; > + > + if (testObjectType(int16Obj, "int16_t", Type::Int16) != TestPass) > + return TestFail; > + > + if (testIntegerObject(int16Obj, "int16_t", Type::Int16, -1000) != TestPass) > + return TestFail; > + > + /* Test uint16_t object */ > + auto &uint16Obj = (*root)["uint16_t"]; > + > + if (testObjectType(uint16Obj, "uint16_t", Type::UInt16) != TestPass) > + return TestFail; > + > + if (testIntegerObject(uint16Obj, "uint16_t", Type::UInt16, 1000) != TestPass) > + return TestFail; > + > /* Test int32_t object */ > auto &int32Obj = (*root)["int32_t"]; > > if (testObjectType(int32Obj, "int32_t", Type::Int32) != TestPass) > return TestFail; > > - if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100) != TestPass) > + if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100000) != TestPass) > return TestFail; > > /* Test uint32_t object */ > @@ -270,7 +329,7 @@ protected: > if (testObjectType(uint32Obj, "uint32_t", Type::UInt32) != TestPass) > return TestFail; > > - if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100) != TestPass) > + if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100000) != TestPass) > return TestFail; > > /* Test double value */ > -- > Regards, > > Laurent Pinchart >
Hi Laurent On Tue, Aug 16, 2022 at 04:54:08AM +0300, Laurent Pinchart via libcamera-devel wrote: > Add 16-bit integer parsing tests, including a test to verify the > out-of-range checks when parsing 32-bit integers as 16-bit values. That > test currently fails. > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org> Thanks j > --- > test/yaml-parser.cpp | 77 ++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 68 insertions(+), 9 deletions(-) > > diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp > index 803e70beb782..28f8cc8822b3 100644 > --- a/test/yaml-parser.cpp > +++ b/test/yaml-parser.cpp > @@ -24,8 +24,10 @@ using namespace std; > static const string testYaml = > "string: libcamera\n" > "double: 3.14159\n" > - "uint32_t: 100\n" > - "int32_t: -100\n" > + "int16_t: -1000\n" > + "uint16_t: 1000\n" > + "int32_t: -100000\n" > + "uint32_t: 100000\n" > "size: [1920, 1080]\n" > "list:\n" > " - James\n" > @@ -74,6 +76,8 @@ protected: > > enum class Type { > String, > + Int16, > + UInt16, > Int32, > UInt32, > Double, > @@ -86,8 +90,10 @@ protected: > { > bool isList = type == Type::List || type == Type::Size; > bool isScalar = !isList && type != Type::Dictionary; > - bool isInteger = type == Type::Int32 || type == Type::UInt32; > - bool isSigned = type == Type::Int32; > + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; > + bool isInteger32 = type == Type::Int32 || type == Type::UInt32; > + bool isInteger = isInteger16 || isInteger32; > + bool isSigned = type == Type::Int16 || type == Type::Int32; > > if ((isScalar && !obj.isValue()) || (!isScalar && obj.isValue())) { > std::cerr > @@ -118,6 +124,20 @@ protected: > return TestFail; > } > > + if (!isInteger16 && obj.get<int16_t>()) { > + std::cerr > + << "Object " << name << " didn't fail to parse as " > + << "int16_t" << std::endl; > + return TestFail; > + } > + > + if ((!isInteger16 || isSigned) && obj.get<uint16_t>()) { > + std::cerr > + << "Object " << name << " didn't fail to parse as " > + << "uint16_t" << std::endl; > + return TestFail; > + } > + > if (!isInteger && obj.get<int32_t>()) { > std::cerr > << "Object " << name << " didn't fail to parse as " > @@ -154,7 +174,8 @@ protected: > { > uint64_t unsignedValue = static_cast<uint64_t>(value); > std::string strValue = std::to_string(value); > - bool isSigned = type == Type::Int32; > + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; > + bool isSigned = type == Type::Int16 || type == Type::Int32; > > /* All integers can be parsed as strings or double. */ > > @@ -174,6 +195,26 @@ protected: > return TestFail; > } > > + if (isInteger16) { > + if (obj.get<int16_t>().value_or(0) != value || > + obj.get<int16_t>(0) != value) { > + std::cerr > + << "Object " << name << " failed to parse as " > + << "int16_t" << std::endl; > + return TestFail; > + } > + } > + > + if (isInteger16 && !isSigned) { > + if (obj.get<uint16_t>().value_or(0) != unsignedValue || > + obj.get<uint16_t>(0) != unsignedValue) { > + std::cerr > + << "Object " << name << " failed to parse as " > + << "uint16_t" << std::endl; > + return TestFail; > + } > + } > + > if (obj.get<int32_t>().value_or(0) != value || > obj.get<int32_t>(0) != value) { > std::cerr > @@ -231,8 +272,8 @@ protected: > } > > std::vector<const char *> rootElemNames = { > - "string", "double", "int32_t", "uint32_t", "size", > - "list", "dictionary", "level1", > + "string", "double", "int16_t", "uint16_t", "int32_t", > + "uint32_t", "size", "list", "dictionary", "level1", > }; > > for (const char *name : rootElemNames) { > @@ -255,13 +296,31 @@ protected: > return TestFail; > } > > + /* Test int16_t object */ > + auto &int16Obj = (*root)["int16_t"]; > + > + if (testObjectType(int16Obj, "int16_t", Type::Int16) != TestPass) > + return TestFail; > + > + if (testIntegerObject(int16Obj, "int16_t", Type::Int16, -1000) != TestPass) > + return TestFail; > + > + /* Test uint16_t object */ > + auto &uint16Obj = (*root)["uint16_t"]; > + > + if (testObjectType(uint16Obj, "uint16_t", Type::UInt16) != TestPass) > + return TestFail; > + > + if (testIntegerObject(uint16Obj, "uint16_t", Type::UInt16, 1000) != TestPass) > + return TestFail; > + > /* Test int32_t object */ > auto &int32Obj = (*root)["int32_t"]; > > if (testObjectType(int32Obj, "int32_t", Type::Int32) != TestPass) > return TestFail; > > - if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100) != TestPass) > + if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100000) != TestPass) > return TestFail; > > /* Test uint32_t object */ > @@ -270,7 +329,7 @@ protected: > if (testObjectType(uint32Obj, "uint32_t", Type::UInt32) != TestPass) > return TestFail; > > - if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100) != TestPass) > + if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100000) != TestPass) > return TestFail; > > /* Test double value */ > -- > Regards, > > Laurent Pinchart >
Hi Paul, On Thu, Aug 18, 2022 at 09:21:01PM +0900, paul.elder@ideasonboard.com wrote: > On Tue, Aug 16, 2022 at 04:54:08AM +0300, Laurent Pinchart via libcamera-devel wrote: > > Add 16-bit integer parsing tests, including a test to verify the > > out-of-range checks when parsing 32-bit integers as 16-bit values. That > > I can't find the test for the out-of-range checks...? Or is it not added > because it fails? See below... > > test currently fails. > > > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > --- > > test/yaml-parser.cpp | 77 ++++++++++++++++++++++++++++++++++++++------ > > 1 file changed, 68 insertions(+), 9 deletions(-) > > > > diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp > > index 803e70beb782..28f8cc8822b3 100644 > > --- a/test/yaml-parser.cpp > > +++ b/test/yaml-parser.cpp > > @@ -24,8 +24,10 @@ using namespace std; > > static const string testYaml = > > "string: libcamera\n" > > "double: 3.14159\n" > > - "uint32_t: 100\n" > > - "int32_t: -100\n" > > + "int16_t: -1000\n" > > + "uint16_t: 1000\n" > > + "int32_t: -100000\n" > > + "uint32_t: 100000\n" > > "size: [1920, 1080]\n" > > "list:\n" > > " - James\n" > > @@ -74,6 +76,8 @@ protected: > > > > enum class Type { > > String, > > + Int16, > > + UInt16, > > Int32, > > UInt32, > > Double, > > @@ -86,8 +90,10 @@ protected: > > { > > bool isList = type == Type::List || type == Type::Size; > > bool isScalar = !isList && type != Type::Dictionary; > > - bool isInteger = type == Type::Int32 || type == Type::UInt32; > > - bool isSigned = type == Type::Int32; > > + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; > > + bool isInteger32 = type == Type::Int32 || type == Type::UInt32; > > + bool isInteger = isInteger16 || isInteger32; > > + bool isSigned = type == Type::Int16 || type == Type::Int32; > > > > if ((isScalar && !obj.isValue()) || (!isScalar && obj.isValue())) { > > std::cerr > > @@ -118,6 +124,20 @@ protected: > > return TestFail; > > } > > > > + if (!isInteger16 && obj.get<int16_t>()) { > > + std::cerr > > + << "Object " << name << " didn't fail to parse as " > > + << "int16_t" << std::endl; > > + return TestFail; > > + } Here. This fails with the int32_t and uint32_t, obj.get<int16_t>() should return nullopt in those cases, and it doesn't. > > + > > + if ((!isInteger16 || isSigned) && obj.get<uint16_t>()) { > > + std::cerr > > + << "Object " << name << " didn't fail to parse as " > > + << "uint16_t" << std::endl; > > + return TestFail; > > + } > > + > > if (!isInteger && obj.get<int32_t>()) { > > std::cerr > > << "Object " << name << " didn't fail to parse as " > > @@ -154,7 +174,8 @@ protected: > > { > > uint64_t unsignedValue = static_cast<uint64_t>(value); > > std::string strValue = std::to_string(value); > > - bool isSigned = type == Type::Int32; > > + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; > > + bool isSigned = type == Type::Int16 || type == Type::Int32; > > > > /* All integers can be parsed as strings or double. */ > > > > @@ -174,6 +195,26 @@ protected: > > return TestFail; > > } > > > > + if (isInteger16) { > > + if (obj.get<int16_t>().value_or(0) != value || > > + obj.get<int16_t>(0) != value) { > > + std::cerr > > + << "Object " << name << " failed to parse as " > > + << "int16_t" << std::endl; > > + return TestFail; > > + } > > + } > > + > > + if (isInteger16 && !isSigned) { > > + if (obj.get<uint16_t>().value_or(0) != unsignedValue || > > + obj.get<uint16_t>(0) != unsignedValue) { > > + std::cerr > > + << "Object " << name << " failed to parse as " > > + << "uint16_t" << std::endl; > > + return TestFail; > > + } > > + } > > + > > if (obj.get<int32_t>().value_or(0) != value || > > obj.get<int32_t>(0) != value) { > > std::cerr > > @@ -231,8 +272,8 @@ protected: > > } > > > > std::vector<const char *> rootElemNames = { > > - "string", "double", "int32_t", "uint32_t", "size", > > - "list", "dictionary", "level1", > > + "string", "double", "int16_t", "uint16_t", "int32_t", > > + "uint32_t", "size", "list", "dictionary", "level1", > > }; > > > > for (const char *name : rootElemNames) { > > @@ -255,13 +296,31 @@ protected: > > return TestFail; > > } > > > > + /* Test int16_t object */ > > + auto &int16Obj = (*root)["int16_t"]; > > + > > + if (testObjectType(int16Obj, "int16_t", Type::Int16) != TestPass) > > + return TestFail; > > + > > + if (testIntegerObject(int16Obj, "int16_t", Type::Int16, -1000) != TestPass) > > + return TestFail; > > + > > + /* Test uint16_t object */ > > + auto &uint16Obj = (*root)["uint16_t"]; > > + > > + if (testObjectType(uint16Obj, "uint16_t", Type::UInt16) != TestPass) > > + return TestFail; > > + > > + if (testIntegerObject(uint16Obj, "uint16_t", Type::UInt16, 1000) != TestPass) > > + return TestFail; > > + > > /* Test int32_t object */ > > auto &int32Obj = (*root)["int32_t"]; > > > > if (testObjectType(int32Obj, "int32_t", Type::Int32) != TestPass) > > return TestFail; > > > > - if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100) != TestPass) > > + if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100000) != TestPass) > > return TestFail; > > > > /* Test uint32_t object */ > > @@ -270,7 +329,7 @@ protected: > > if (testObjectType(uint32Obj, "uint32_t", Type::UInt32) != TestPass) > > return TestFail; > > > > - if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100) != TestPass) > > + if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100000) != TestPass) > > return TestFail; > > > > /* Test double value */
Hi Laurent, On Thu, Aug 18, 2022 at 05:39:19PM +0300, Laurent Pinchart wrote: > Hi Paul, > > On Thu, Aug 18, 2022 at 09:21:01PM +0900, paul.elder@ideasonboard.com wrote: > > On Tue, Aug 16, 2022 at 04:54:08AM +0300, Laurent Pinchart via libcamera-devel wrote: > > > Add 16-bit integer parsing tests, including a test to verify the > > > out-of-range checks when parsing 32-bit integers as 16-bit values. That > > > > I can't find the test for the out-of-range checks...? Or is it not added > > because it fails? > > See below... > > > > test currently fails. > > > > > > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> > > > --- > > > test/yaml-parser.cpp | 77 ++++++++++++++++++++++++++++++++++++++------ > > > 1 file changed, 68 insertions(+), 9 deletions(-) > > > > > > diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp > > > index 803e70beb782..28f8cc8822b3 100644 > > > --- a/test/yaml-parser.cpp > > > +++ b/test/yaml-parser.cpp > > > @@ -24,8 +24,10 @@ using namespace std; > > > static const string testYaml = > > > "string: libcamera\n" > > > "double: 3.14159\n" > > > - "uint32_t: 100\n" > > > - "int32_t: -100\n" > > > + "int16_t: -1000\n" > > > + "uint16_t: 1000\n" > > > + "int32_t: -100000\n" > > > + "uint32_t: 100000\n" > > > "size: [1920, 1080]\n" > > > "list:\n" > > > " - James\n" > > > @@ -74,6 +76,8 @@ protected: > > > > > > enum class Type { > > > String, > > > + Int16, > > > + UInt16, > > > Int32, > > > UInt32, > > > Double, > > > @@ -86,8 +90,10 @@ protected: > > > { > > > bool isList = type == Type::List || type == Type::Size; > > > bool isScalar = !isList && type != Type::Dictionary; > > > - bool isInteger = type == Type::Int32 || type == Type::UInt32; > > > - bool isSigned = type == Type::Int32; > > > + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; > > > + bool isInteger32 = type == Type::Int32 || type == Type::UInt32; > > > + bool isInteger = isInteger16 || isInteger32; > > > + bool isSigned = type == Type::Int16 || type == Type::Int32; > > > > > > if ((isScalar && !obj.isValue()) || (!isScalar && obj.isValue())) { > > > std::cerr > > > @@ -118,6 +124,20 @@ protected: > > > return TestFail; > > > } > > > > > > + if (!isInteger16 && obj.get<int16_t>()) { > > > + std::cerr > > > + << "Object " << name << " didn't fail to parse as " > > > + << "int16_t" << std::endl; > > > + return TestFail; > > > + } > > Here. This fails with the int32_t and uint32_t, obj.get<int16_t>() > should return nullopt in those cases, and it doesn't. Ah, I see. Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> > > > > + > > > + if ((!isInteger16 || isSigned) && obj.get<uint16_t>()) { > > > + std::cerr > > > + << "Object " << name << " didn't fail to parse as " > > > + << "uint16_t" << std::endl; > > > + return TestFail; > > > + } > > > + > > > if (!isInteger && obj.get<int32_t>()) { > > > std::cerr > > > << "Object " << name << " didn't fail to parse as " > > > @@ -154,7 +174,8 @@ protected: > > > { > > > uint64_t unsignedValue = static_cast<uint64_t>(value); > > > std::string strValue = std::to_string(value); > > > - bool isSigned = type == Type::Int32; > > > + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; > > > + bool isSigned = type == Type::Int16 || type == Type::Int32; > > > > > > /* All integers can be parsed as strings or double. */ > > > > > > @@ -174,6 +195,26 @@ protected: > > > return TestFail; > > > } > > > > > > + if (isInteger16) { > > > + if (obj.get<int16_t>().value_or(0) != value || > > > + obj.get<int16_t>(0) != value) { > > > + std::cerr > > > + << "Object " << name << " failed to parse as " > > > + << "int16_t" << std::endl; > > > + return TestFail; > > > + } > > > + } > > > + > > > + if (isInteger16 && !isSigned) { > > > + if (obj.get<uint16_t>().value_or(0) != unsignedValue || > > > + obj.get<uint16_t>(0) != unsignedValue) { > > > + std::cerr > > > + << "Object " << name << " failed to parse as " > > > + << "uint16_t" << std::endl; > > > + return TestFail; > > > + } > > > + } > > > + > > > if (obj.get<int32_t>().value_or(0) != value || > > > obj.get<int32_t>(0) != value) { > > > std::cerr > > > @@ -231,8 +272,8 @@ protected: > > > } > > > > > > std::vector<const char *> rootElemNames = { > > > - "string", "double", "int32_t", "uint32_t", "size", > > > - "list", "dictionary", "level1", > > > + "string", "double", "int16_t", "uint16_t", "int32_t", > > > + "uint32_t", "size", "list", "dictionary", "level1", > > > }; > > > > > > for (const char *name : rootElemNames) { > > > @@ -255,13 +296,31 @@ protected: > > > return TestFail; > > > } > > > > > > + /* Test int16_t object */ > > > + auto &int16Obj = (*root)["int16_t"]; > > > + > > > + if (testObjectType(int16Obj, "int16_t", Type::Int16) != TestPass) > > > + return TestFail; > > > + > > > + if (testIntegerObject(int16Obj, "int16_t", Type::Int16, -1000) != TestPass) > > > + return TestFail; > > > + > > > + /* Test uint16_t object */ > > > + auto &uint16Obj = (*root)["uint16_t"]; > > > + > > > + if (testObjectType(uint16Obj, "uint16_t", Type::UInt16) != TestPass) > > > + return TestFail; > > > + > > > + if (testIntegerObject(uint16Obj, "uint16_t", Type::UInt16, 1000) != TestPass) > > > + return TestFail; > > > + > > > /* Test int32_t object */ > > > auto &int32Obj = (*root)["int32_t"]; > > > > > > if (testObjectType(int32Obj, "int32_t", Type::Int32) != TestPass) > > > return TestFail; > > > > > > - if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100) != TestPass) > > > + if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100000) != TestPass) > > > return TestFail; > > > > > > /* Test uint32_t object */ > > > @@ -270,7 +329,7 @@ protected: > > > if (testObjectType(uint32Obj, "uint32_t", Type::UInt32) != TestPass) > > > return TestFail; > > > > > > - if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100) != TestPass) > > > + if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100000) != TestPass) > > > return TestFail; > > > > > > /* Test double value */
diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 803e70beb782..28f8cc8822b3 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -24,8 +24,10 @@ using namespace std; static const string testYaml = "string: libcamera\n" "double: 3.14159\n" - "uint32_t: 100\n" - "int32_t: -100\n" + "int16_t: -1000\n" + "uint16_t: 1000\n" + "int32_t: -100000\n" + "uint32_t: 100000\n" "size: [1920, 1080]\n" "list:\n" " - James\n" @@ -74,6 +76,8 @@ protected: enum class Type { String, + Int16, + UInt16, Int32, UInt32, Double, @@ -86,8 +90,10 @@ protected: { bool isList = type == Type::List || type == Type::Size; bool isScalar = !isList && type != Type::Dictionary; - bool isInteger = type == Type::Int32 || type == Type::UInt32; - bool isSigned = type == Type::Int32; + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; + bool isInteger32 = type == Type::Int32 || type == Type::UInt32; + bool isInteger = isInteger16 || isInteger32; + bool isSigned = type == Type::Int16 || type == Type::Int32; if ((isScalar && !obj.isValue()) || (!isScalar && obj.isValue())) { std::cerr @@ -118,6 +124,20 @@ protected: return TestFail; } + if (!isInteger16 && obj.get<int16_t>()) { + std::cerr + << "Object " << name << " didn't fail to parse as " + << "int16_t" << std::endl; + return TestFail; + } + + if ((!isInteger16 || isSigned) && obj.get<uint16_t>()) { + std::cerr + << "Object " << name << " didn't fail to parse as " + << "uint16_t" << std::endl; + return TestFail; + } + if (!isInteger && obj.get<int32_t>()) { std::cerr << "Object " << name << " didn't fail to parse as " @@ -154,7 +174,8 @@ protected: { uint64_t unsignedValue = static_cast<uint64_t>(value); std::string strValue = std::to_string(value); - bool isSigned = type == Type::Int32; + bool isInteger16 = type == Type::Int16 || type == Type::UInt16; + bool isSigned = type == Type::Int16 || type == Type::Int32; /* All integers can be parsed as strings or double. */ @@ -174,6 +195,26 @@ protected: return TestFail; } + if (isInteger16) { + if (obj.get<int16_t>().value_or(0) != value || + obj.get<int16_t>(0) != value) { + std::cerr + << "Object " << name << " failed to parse as " + << "int16_t" << std::endl; + return TestFail; + } + } + + if (isInteger16 && !isSigned) { + if (obj.get<uint16_t>().value_or(0) != unsignedValue || + obj.get<uint16_t>(0) != unsignedValue) { + std::cerr + << "Object " << name << " failed to parse as " + << "uint16_t" << std::endl; + return TestFail; + } + } + if (obj.get<int32_t>().value_or(0) != value || obj.get<int32_t>(0) != value) { std::cerr @@ -231,8 +272,8 @@ protected: } std::vector<const char *> rootElemNames = { - "string", "double", "int32_t", "uint32_t", "size", - "list", "dictionary", "level1", + "string", "double", "int16_t", "uint16_t", "int32_t", + "uint32_t", "size", "list", "dictionary", "level1", }; for (const char *name : rootElemNames) { @@ -255,13 +296,31 @@ protected: return TestFail; } + /* Test int16_t object */ + auto &int16Obj = (*root)["int16_t"]; + + if (testObjectType(int16Obj, "int16_t", Type::Int16) != TestPass) + return TestFail; + + if (testIntegerObject(int16Obj, "int16_t", Type::Int16, -1000) != TestPass) + return TestFail; + + /* Test uint16_t object */ + auto &uint16Obj = (*root)["uint16_t"]; + + if (testObjectType(uint16Obj, "uint16_t", Type::UInt16) != TestPass) + return TestFail; + + if (testIntegerObject(uint16Obj, "uint16_t", Type::UInt16, 1000) != TestPass) + return TestFail; + /* Test int32_t object */ auto &int32Obj = (*root)["int32_t"]; if (testObjectType(int32Obj, "int32_t", Type::Int32) != TestPass) return TestFail; - if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100) != TestPass) + if (testIntegerObject(int32Obj, "int32_t", Type::Int32, -100000) != TestPass) return TestFail; /* Test uint32_t object */ @@ -270,7 +329,7 @@ protected: if (testObjectType(uint32Obj, "uint32_t", Type::UInt32) != TestPass) return TestFail; - if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100) != TestPass) + if (testIntegerObject(uint32Obj, "uint32_t", Type::UInt32, 100000) != TestPass) return TestFail; /* Test double value */
Add 16-bit integer parsing tests, including a test to verify the out-of-range checks when parsing 32-bit integers as 16-bit values. That test currently fails. Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> --- test/yaml-parser.cpp | 77 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 68 insertions(+), 9 deletions(-)