summaryrefslogtreecommitdiff
path: root/tests/codec-json.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/codec-json.cpp')
-rw-r--r--tests/codec-json.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/tests/codec-json.cpp b/tests/codec-json.cpp
index 1c77f46..030b1e4 100644
--- a/tests/codec-json.cpp
+++ b/tests/codec-json.cpp
@@ -25,6 +25,127 @@ using TestStruct = Struct<
Member<String, "bar">
>;
}
+
+SAW_TEST("UInt8 write"){
+ using namespace saw;
+ data<schema::UInt8, encode::Native> native_int;
+ data<schema::UInt8, encode::Json> json_int;
+
+ native_int.set(121);
+
+ codec<schema::UInt8, encode::Json> json_codec;
+
+ error_or<void> eov = json_codec.encode(native_int, json_int);
+ SAW_EXPECT(eov.is_value(), "Encoding error");
+
+ /**
+ * Currently doing this manually. Technically I should convert to std::string for tests
+ */
+ std::string_view str_v = "121";
+ std::string enc_val = convert_to_string(json_int.get_buffer());
+ SAW_EXPECT( enc_val == str_v, std::string{"Value is not being encoded correctly. Encoded: "} + enc_val );
+}
+
+SAW_TEST("UInt16 write"){
+ using namespace saw;
+ data<schema::UInt16, encode::Native> native_int;
+ data<schema::UInt16, encode::Json> json_int;
+
+ native_int.set(24413);
+
+ codec<schema::UInt16, encode::Json> json_codec;
+
+ error_or<void> eov = json_codec.encode(native_int, json_int);
+ SAW_EXPECT(eov.is_value(), "Encoding error");
+
+ /**
+ * Currently doing this manually. Technically I should convert to std::string for tests
+ */
+ std::string_view str_v = "24413";
+ std::string enc_val = convert_to_string(json_int.get_buffer());
+ SAW_EXPECT( enc_val == str_v, std::string{"Value is not being encoded correctly. Encoded: "} + enc_val );
+}
+
+SAW_TEST("UInt32 write"){
+ using namespace saw;
+ data<schema::UInt32, encode::Native> native_int;
+ data<schema::UInt32, encode::Json> json_int;
+
+ native_int.set(44123);
+
+ codec<schema::UInt32, encode::Json> json_codec;
+
+ error_or<void> eov = json_codec.encode(native_int, json_int);
+ SAW_EXPECT(eov.is_value(), "Encoding error");
+
+ /**
+ * Currently doing this manually. Technically I should convert to std::string for tests
+ */
+ std::string_view str_v = "44123";
+ std::string enc_val = convert_to_string(json_int.get_buffer());
+ SAW_EXPECT( enc_val == str_v, std::string{"Value is not being encoded correctly. Encoded: "} + enc_val );
+}
+
+SAW_TEST("UInt64 write"){
+ using namespace saw;
+ data<schema::UInt64, encode::Native> native_int;
+ data<schema::UInt64, encode::Json> json_int;
+
+ native_int.set(243345543);
+
+ codec<schema::UInt64, encode::Json> json_codec;
+
+ error_or<void> eov = json_codec.encode(native_int, json_int);
+ SAW_EXPECT(eov.is_value(), "Encoding error");
+
+ /**
+ * Currently doing this manually. Technically I should convert to std::string for tests
+ */
+ std::string_view str_v = "243345543";
+ std::string enc_val = convert_to_string(json_int.get_buffer());
+ SAW_EXPECT( enc_val == str_v, std::string{"Value is not being encoded correctly. Encoded: "} + enc_val );
+}
+
+SAW_TEST("Int8 write"){
+ using namespace saw;
+ data<schema::Int8, encode::Native> native_int;
+ data<schema::Int8, encode::Json> json_int;
+
+ native_int.set(-121);
+
+ codec<schema::Int8, encode::Json> json_codec;
+
+ error_or<void> eov = json_codec.encode(native_int, json_int);
+ SAW_EXPECT(eov.is_value(), "Encoding error");
+
+ /**
+ * Currently doing this manually. Technically I should convert to std::string for tests
+ */
+ std::string_view str_v = "-121";
+ std::string enc_val = convert_to_string(json_int.get_buffer());
+ SAW_EXPECT( enc_val == str_v, std::string{"Value is not being encoded correctly. Encoded: "} + enc_val );
+}
+
+SAW_TEST("Int16 write"){
+ using namespace saw;
+ data<schema::Int16, encode::Native> native_int;
+ data<schema::Int16, encode::Json> json_int;
+
+ native_int.set(-24413);
+
+ codec<schema::Int16, encode::Json> json_codec;
+
+ error_or<void> eov = json_codec.encode(native_int, json_int);
+ SAW_EXPECT(eov.is_value(), "Encoding error");
+
+ /**
+ * Currently doing this manually. Technically I should convert to std::string for tests
+ */
+ std::string_view str_v = "-24413";
+ std::string enc_val = convert_to_string(json_int.get_buffer());
+ SAW_EXPECT( enc_val == str_v, std::string{"Value is not being encoded correctly. Encoded: "} + enc_val );
+}
+
SAW_TEST("Int32 write"){
using namespace saw;
data<schema::Int32, encode::Native> native_int;
@@ -45,6 +166,26 @@ SAW_TEST("Int32 write"){
SAW_EXPECT( enc_val == str_v, std::string{"Value is not being encoded correctly. Encoded: "} + enc_val );
}
+SAW_TEST("Int64 write"){
+ using namespace saw;
+ data<schema::Int64, encode::Native> native_int;
+ data<schema::Int64, encode::Json> json_int;
+
+ native_int.set(243345543);
+
+ codec<schema::Int64, encode::Json> json_codec;
+
+ error_or<void> eov = json_codec.encode(native_int, json_int);
+ SAW_EXPECT(eov.is_value(), "Encoding error");
+
+ /**
+ * Currently doing this manually. Technically I should convert to std::string for tests
+ */
+ std::string_view str_v = "243345543";
+ std::string enc_val = convert_to_string(json_int.get_buffer());
+ SAW_EXPECT( enc_val == str_v, std::string{"Value is not being encoded correctly. Encoded: "} + enc_val );
+}
+
SAW_TEST("String write"){
using namespace saw;
data<schema::String, encode::Native> nat_str;
@@ -147,4 +288,21 @@ SAW_TEST("Struct write"){
SAW_EXPECT(enc_val == str_v, std::string{"Struct not encoded correctly. Encoded: "} + enc_val + std::string{" Expected: "} + std::string{str_v});
}
+
+SAW_TEST("Int8 read"){
+ using namespace saw;
+ data<schema::Int8, encode::Native> native_int;
+ data<schema::Int8, encode::Json> json_int;
+
+ codec<schema::Int8, encode::Json> json_codec;
+
+ error_or<void> eov = json_codec.decode(json_int, native_int);
+ SAW_EXPECT(eov.is_value(), "Encoding error");
+
+ /**
+ * Currently doing this manually. Technically I should convert to std::string for tests
+ */
+ typename native_data_type<schema::Int8>::type dec_val = 43;
+ SAW_EXPECT( dec_val == native_int.get(), std::string{"Value is not being encoded correctly. Encoded: "} + std::to_string(static_cast<int>(native_int.get())));
+}
}