Exemplo n.º 1
0
TEST_F(ParseTest, type_union_no_select_use_small) {
    installMeta(
        "<metalib tagsetversion='1' name='net'  version='1'>"
        "    <union name='S' version='1'>"
        "	     <entry name='a1' type='int16'/>"
        "	     <entry name='a2' type='int32'/>"
        "    </union>"
        "    <struct name='S2' version='1'>"
        "	     <entry name='m_s' type='S'/>"
        "	     <entry name='a2' type='int16'/>"
        "    </struct>"
        "</metalib>"
        );

#pragma pack(push,1)
    struct T {
        union {
            int16_t a1;
            int32_t a2;
        } m_s;
        int16_t a2;
    };
#pragma pack(pop)

    EXPECT_EQ(
        metaSize("S2"),
        read("{ \"m_s\" : { \"a1\" : 12 }, \"a2\" : 14 }", "S2"));

    struct T * r = (struct T*)result();
    ASSERT_TRUE(r);
    EXPECT_EQ(12, r->m_s.a1);
    EXPECT_EQ(14, r->a2);
}
Exemplo n.º 2
0
TEST_F(ParseTest, type_union_no_select_multi_entry) {
    installMeta(
        "<metalib tagsetversion='1' name='net'  version='1'>"
        "    <union name='S' version='1'>"
        "	     <entry name='a1' type='int16'/>"
        "	     <entry name='a2' type='int32'/>"
        "    </union>"
        "    <struct name='S2' version='1'>"
        "	     <entry name='m_s' type='S'/>"
        "	     <entry name='a2' type='int16'/>"
        "    </struct>"
        "</metalib>"
        );

#pragma pack(push,1)
    struct {
        union {
            int16_t a1;
            int32_t a2;
        } m_s;
        int16_t a2;
    } expect = { { 13 }, 14  };
#pragma pack(pop)

    ASSERT_EQ(
        metaSize("S2"),
        read("{ \"m_s\" : { \"a1\" : 12, \"a2\" : 13 }, \"a2\" : 14 }", "S2"));

    ASSERT_JSON_READ_RESULT(expect);
}
Exemplo n.º 3
0
TEST_F(ParseTest, type_union_selector_basic) {
    installMeta(
        "<metalib tagsetversion='1' name='net'  version='1'>"
        "    <union name='S' version='1'>"
        "	     <entry name='a1' type='int16' id='3'/>"
        "	     <entry name='a2' type='int32' id='4'/>"
        "    </union>"
        "    <struct name='S2' version='1'>"
        "	     <entry name='s' type='int16'/>"
        "	     <entry name='u' type='S' select='s'/>"
        "    </struct>"
        "</metalib>"
        );

#pragma pack(push,1)
    struct T {
        int16_t s;
        union {
            int16_t a1;
            int32_t a2;
        } u;
    };
#pragma pack(pop)

    ASSERT_EQ(
        4,
        read("{ \"s\" : 3, \"u\" : { \"a1\" : 12, \"a2\" : 13 } }", "S2"));

    struct T * r = (struct T*)result();
    ASSERT_TRUE(r);
    EXPECT_EQ(3, r->s);
    EXPECT_EQ(12, r->u.a1);

}
Exemplo n.º 4
0
TEST_F(WriteTest, type_struct_basic) {
    installMeta(
        "<metalib tagsetversion='1' name='net'  version='1'>"
        "    <struct name='S1' version='1'>"
        "	     <entry name='a1' type='uint32' id='1'/>"
        "    </struct>"
        "    <struct name='S2' version='1'>"
        "	     <entry name='b1' type='S1' id='3'/>"
        "    </struct>"
        "</metalib>"
        );

    EXPECT_EQ(5, write("S2", "b1: { a1: 150 }"));
    
    EXPECT_STREQ(
        "0x1A 0x03 0x08 0x96 0x01", result());
}
Exemplo n.º 5
0
TEST_F(WriteTest, type_struct_array) {
    installMeta(
        "<metalib tagsetversion='1' name='net'  version='1'>"
        "    <struct name='S1' version='1'>"
        "	     <entry name='a1' type='uint32' id='1' count='2'/>"
        "    </struct>"
        "    <struct name='S2' version='1'>"
        "	     <entry name='b1' type='S1' id='3'/>"
        "    </struct>"
        "</metalib>"
        );

    EXPECT_EQ(8, write("S2", "b1: { a1: [150, 151] }"));
    
    EXPECT_STREQ(
        "0x1A 0x06 0x0A 0x04 0x96 0x01 0x97 0x01", result());
}
Exemplo n.º 6
0
TEST_F(WriteTest, type_union_no_select) {
    installMeta(
        "<metalib tagsetversion='1' name='net'  version='1'>"
        "    <union name='U1' version='1'>"
        "	     <entry name='a1' type='uint32' id='1'/>"
        "	     <entry name='a2' type='uint32' id='2'/>"
        "    </union>"
        "    <struct name='S2' version='1'>"
        "	     <entry name='b1' type='U1' id='3'/>"
        "    </struct>"
        "</metalib>"
        );

    EXPECT_EQ(8, write("S2", "b1: { a1: 150 }"));
    
    EXPECT_STREQ(
        "0x1A 0x06 0x08 0x96 0x01 0x10 0x96 0x01"
        , result());
}
Exemplo n.º 7
0
TEST_F(ReadTest, struct_basic) {
    installMeta(
        "<metalib tagsetversion='1' name='net'  version='1'>"
        "    <struct name='I' version='1'>"
        "	     <entry name='a1' type='uint32' id='1'/>"
        "    </struct>"
        "    <struct name='S' version='1'>"
        "	     <entry name='b1' type='I' id='1'/>"
        "    </struct>"
        "</metalib>"
        );

    EXPECT_EQ(4, read("S", "b1: { a1: 150 }"));

    EXPECT_CFG_EQ(
        "b1: { a1: 150 }"
        ,
        result());
}
Exemplo n.º 8
0
TEST_F(ReadTest, union_no_select) {
    installMeta(
        "<metalib tagsetversion='1' name='net'  version='1'>"
        "    <union name='U1' version='1'>"
        "	     <entry name='a1' type='uint32' id='1'/>"
        "	     <entry name='a2' type='uint32' id='2'/>"
        "    </union>"
        "    <struct name='S2' version='1'>"
        "	     <entry name='b1' type='U1' id='3'/>"
        "    </struct>"
        "</metalib>"
        );

    EXPECT_EQ(4, read("S2", "b1: { a1: 150 }"));
    
    EXPECT_CFG_EQ(
        "b1: { a1: 150, a2: 150 }"
        ,
        result());
}
Exemplo n.º 9
0
TEST_F(ParseTest, type_union_root) {
    installMeta(
        "<metalib tagsetversion='1' name='net'  version='1'>"
        "    <union name='S' version='1'>"
        "	     <entry name='a1' type='int16'/>"
        "	     <entry name='a2' type='int32'/>"
        "    </union>"
        "</metalib>"
        );

#pragma pack(push,1)
    union {
        int16_t a1;
        int32_t a2;
    } expect = { 12 };
#pragma pack(pop)

    ASSERT_EQ(metaSize("S"), read("{ \"a2\" : 12}", "S"));

    ASSERT_JSON_READ_RESULT(expect);
}