Skip to content

Commit

Permalink
update test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangjipeng committed Feb 19, 2025
1 parent d8fe6a1 commit 2904d88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
1 change: 0 additions & 1 deletion ext/svg/psx_xml_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ static INLINE bool _psx_proc_entity(xml_token_state_t* state, psx_xml_token_t* t
char ch = *(state->cur);
if (ch == 'x' || ch == 'X') {
_psx_set_entity_state(state, HEX_DECIMAL);
continue;
} else if (ch >= '0' && ch <= '9') {
_psx_set_entity_state(state, DECIMAL);
continue;
Expand Down
23 changes: 22 additions & 1 deletion unit_tests/ext_xml_token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ static bool _token_process(void* data, const psx_xml_token_t* token)
} else if (token->type == PSX_XML_CONTENT || token->type == PSX_XML_END) {
EXPECT_TRUE(token->end > token->start);
EXPECT_EQ(token->attrs.size, 0);
} else if (token->type == PSX_XML_ENTITY) {
EXPECT_TRUE(token->end > token->start);
EXPECT_EQ(token->attrs.size, 0);
}
return true;
}
Expand Down Expand Up @@ -96,11 +99,14 @@ TEST(PsxXmlTokenTest, TestQuoteValue)
const char* xml_data = "<root><children attr1=\"value1\" attr2='value2' attr3=value3/></root>";
psx_xml_tokenizer(xml_data, (uint32_t)strlen(xml_data), _token_process, nullptr);

const char* xml_data2 = "<root><children attr1=/></root>"; // no value
const char* xml_data2 = "<root><children attr1= attr2=\"\" attr3=''/></root>"; // no value
psx_xml_tokenizer(xml_data2, (uint32_t)strlen(xml_data2), _token_process, nullptr);

const char* xml_data3 = "<root><children checked/></root>"; // no attrname
psx_xml_tokenizer(xml_data3, (uint32_t)strlen(xml_data3), _token_process, nullptr);

const char* xml_data4 = "<root><children attr1=\" attr2='/></root>"; // bad case
psx_xml_tokenizer(xml_data4, (uint32_t)strlen(xml_data4), _token_process, nullptr);
}

TEST(PsxXmlTokenTest, TestComment)
Expand All @@ -109,6 +115,21 @@ TEST(PsxXmlTokenTest, TestComment)
psx_xml_tokenizer(xml_data, (uint32_t)strlen(xml_data), _token_process, nullptr);
}

TEST(PsxXmlTokenTest, TestEntity)
{
const char* xml_data = "<root><children>start &amp; &AMP; contents</children></root>";
psx_xml_tokenizer(xml_data, (uint32_t)strlen(xml_data), _token_process, nullptr);

const char* xml_data2 = "<root><children>start &#xA9; &#169; </children></root>";
psx_xml_tokenizer(xml_data2, (uint32_t)strlen(xml_data2), _token_process, nullptr);

const char* xml_data3 = "<root><!ENTITY /><children>content</children></root>";
psx_xml_tokenizer(xml_data3, (uint32_t)strlen(xml_data3), _token_process, nullptr);

const char* xml_data4 = "<root><children>start &#; &# </children></root>"; // bad case
psx_xml_tokenizer(xml_data4, (uint32_t)strlen(xml_data4), _token_process, nullptr);
}

TEST(PsxXmlTokenTest, TestFail)
{
const char* xml_data = "<root></root>";
Expand Down

0 comments on commit 2904d88

Please sign in to comment.