为了规避NDK的Bug,停用异常处理

This commit is contained in:
2024-02-04 21:11:30 +08:00
parent ad6865feef
commit f994bae5cb
3 changed files with 94 additions and 98 deletions

View File

@@ -6,108 +6,94 @@
#include <Order.h>
TEST(Option, ) {
try {
ling::Order order({"-pts", "--all", "--ok"});
const auto pts = order.addOption({"-pts", "--pts"});
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
order.analysis();
ASSERT_TRUE(pts.isOption());
ASSERT_TRUE(all.isOption());
ASSERT_TRUE(ok.isOption());
ASSERT_FALSE(cancel.isOption());
} catch (const std::runtime_error &e) {
std::cout << e.what() << std::endl;
ling::Order order({"-pts", "--all", "--ok"});
const auto pts = order.addOption({"-pts", "--pts"});
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
if (!order.analysis()) {
std::cout << order.getError() << std::endl;
ASSERT_FALSE("解析出错!");
}
ASSERT_TRUE(pts.isOption());
ASSERT_TRUE(all.isOption());
ASSERT_TRUE(ok.isOption());
ASSERT_FALSE(cancel.isOption());
}
TEST(Option, ) {
try {
ling::Order order({"-pts", "hello world!", "--all", "--ok"});
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
order.analysis();
ASSERT_TRUE(all.isOption());
ASSERT_TRUE(ok.isOption());
ASSERT_FALSE(cancel.isOption());
ASSERT_TRUE(pts.getString() == "hello world!");
} catch (const std::runtime_error &e) {
std::cout << e.what() << std::endl;
ling::Order order({"-pts", "hello world!", "--all", "--ok"});
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
if (!order.analysis()) {
std::cout << order.getError() << std::endl;
ASSERT_FALSE("解析出错!");
}
ASSERT_TRUE(all.isOption());
ASSERT_TRUE(ok.isOption());
ASSERT_FALSE(cancel.isOption());
ASSERT_TRUE(pts.getString() == "hello world!");
}
TEST(Option, ) {
try {
ling::Order order({"-pts", "--all", "--ok"});
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
order.analysis();
ASSERT_FALSE("纠正出错!");
} catch (const std::runtime_error &e) {
}
ling::Order order({"-pts", "--all", "--ok"});
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
ASSERT_FALSE(order.analysis());
}
TEST(Option, ) {
try {
ling::Order order({"-pts", "hello world!", "hello!", "--all", "--ok"});
order.addAnonymity(1);
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
order.analysis();
ASSERT_TRUE(all.isOption());
ASSERT_TRUE(ok.isOption());
ASSERT_FALSE(cancel.isOption());
ASSERT_TRUE(pts.getString() == "hello world!");
ASSERT_TRUE(order.getAnonymity().size() == 1);
ASSERT_TRUE(order.getAnonymity()[0] == "hello!");
} catch (const std::runtime_error &e) {
std::cout << e.what() << std::endl;
ling::Order order({"-pts", "hello world!", "hello!", "--all", "--ok"});
order.addAnonymity(1);
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
if (!order.analysis()) {
std::cout << order.getError() << std::endl;
ASSERT_FALSE("解析出错!");
}
ASSERT_TRUE(all.isOption());
ASSERT_TRUE(ok.isOption());
ASSERT_FALSE(cancel.isOption());
ASSERT_TRUE(pts.getString() == "hello world!");
ASSERT_TRUE(order.getAnonymity().size() == 1);
ASSERT_TRUE(order.getAnonymity()[0] == "hello!");
}
TEST(Option, 2) {
try {
ling::Order order({"-pts", "hello world!", "hello!", "--all", "--ok", "world"});
order.addAnonymity(2);
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
order.analysis();
ASSERT_TRUE(all.isOption());
ASSERT_TRUE(ok.isOption());
ASSERT_FALSE(cancel.isOption());
ASSERT_TRUE(pts.getString() == "hello world!");
ASSERT_TRUE(order.getAnonymity().size() == 2);
ASSERT_TRUE(order.getAnonymity()[0] == "hello!");
ASSERT_TRUE(order.getAnonymity()[1] == "world");
} catch (const std::runtime_error &e) {
std::cout << e.what() << std::endl;
ling::Order order({"-pts", "hello world!", "hello!", "--all", "--ok", "world"});
order.addAnonymity(2);
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
if (!order.analysis()) {
std::cout << order.getError() << std::endl;
ASSERT_FALSE("解析出错!");
}
ASSERT_TRUE(all.isOption());
ASSERT_TRUE(ok.isOption());
ASSERT_FALSE(cancel.isOption());
ASSERT_TRUE(pts.getString() == "hello world!");
ASSERT_TRUE(order.getAnonymity().size() == 2);
ASSERT_TRUE(order.getAnonymity()[0] == "hello!");
ASSERT_TRUE(order.getAnonymity()[1] == "world");
}
TEST(Option, 3) {
try {
ling::Order order({"-pts", "hello world!", "hello!", "--all", "--ok", "world"});
order.addAnonymity(1);
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
order.analysis();
ling::Order order({"-pts", "hello world!", "hello!", "--all", "--ok", "world"});
order.addAnonymity(1);
const auto pts = order.addOption({"-pts", "--pts"}, ling::Order::Type::STRING);
const auto all = order.addOption({"-all", "--all"});
const auto ok = order.addOption({"--ok", "-ok"});
const auto cancel = order.addOption({"--cancel"});
if (order.analysis())
ASSERT_FALSE("匿名参数数量超出限制,但是没有抛出异常!");
} catch (const std::runtime_error &e) {
}
}