Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-oly committed May 23, 2024
2 parents c2efbd3 + cd57d17 commit 69aa913
Showing 1 changed file with 33 additions and 47 deletions.
80 changes: 33 additions & 47 deletions executors/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@
* and returns results via STDOUT.
*/

const char gHelpString[] =
"usage: executor"
"-help Display this message.\n"
"-debug n Level of debug - default = -1\n"
;

#include <iostream>
#include <string>
#include <json-c/json.h>

#include <unicode/utypes.h>
#include <unicode/ucol.h>
#include <unicode/ustring.h>
#include <unicode/uvernum.h>

#include <json-c/json.h>
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
Expand All @@ -47,27 +42,25 @@ extern const string test_list_fmt(json_object *json_in);
extern const string test_numfmt(json_object *json_in);
extern const string TestPluralRules(json_object *json_in);

std::string supported_tests[7] = {
"collation_short",
"datetime_fmt",
"likely_subtags",
"list_fmt",
"lang_names",
"number_fmt",
"plural_rules"
};


std::string cppVersion = "1.0";

/**
* Main -- process command line, call tests or return data
* input is STDIN, output is STDOUT.
* commands start with "#"
* test data is JSON format
*/
int main(int argc, const char** argv)
{
int main(int argc, const char** argv) {
// All the currently supported test types.
std::vector <string> supported_tests;
supported_tests = {
"collation_short",
"datetime_fmt",
"likely_subtags",
"list_fmt",
"lang_names",
"number_fmt",
"plural_rules"
};

for (std::string line; std::getline(cin, line);) {
if (line == "#EXIT") {
return 0;
Expand All @@ -85,47 +78,41 @@ int main(int argc, const char** argv)
// TODO: get from the array of supported tests
json_object *tests_supported = json_object_new_object();
json_object *test_array = json_object_new_array();
for (int index = 0; index < 4; index ++) {
json_object_array_add(test_array,
json_object_new_string(supported_tests[index].c_str()));
for (int index = 0; index < supported_tests.size(); index ++) {
json_object_array_add(
test_array,
json_object_new_string(supported_tests[index].c_str()));
}

json_object_object_add(tests_supported, "supported_tests", test_array);
std::cout << json_object_to_json_string(tests_supported) << endl;
} else {

// Parse the JSON data.
// Get the test type and call the test function.

std::string outputLine;

struct json_object *json_input;
json_input = json_tokener_parse(line.c_str());
json_object *test_type_obj = json_object_object_get(json_input, "test_type");
json_object *test_type_obj =
json_object_object_get(json_input, "test_type");
std::string test_type = json_object_get_string(test_type_obj);

if (test_type == "collation_short" ) {
if (test_type == "collation_short") {
outputLine = test_collator(json_input);
}
else if (test_type == "datetime_fmt") {
outputLine = TestDatetimeFmt(json_input);
}
else if (test_type == "number_fmt") {
outputLine = test_numfmt(json_input);
}
else if (test_type == "likely_subtags") {
} else if (test_type == "datetime_fmt") {
outputLine = TestDatetimeFmt(json_input);
} else if (test_type == "number_fmt") {
outputLine = test_numfmt(json_input);
} else if (test_type == "likely_subtags") {
outputLine = test_likely_subtags(json_input);
}
else if (test_type == "list_fmt") {
} else if (test_type == "list_fmt") {
outputLine = test_list_fmt(json_input);
}
else if (test_type == "lang_names") {
} else if (test_type == "lan1g_names") {
outputLine = test_langnames(json_input);
}
else if (test_type == "plural_rules") {
} else if (test_type == "plural_rules") {
outputLine = TestPluralRules(json_input);
}
else {
} else {
outputLine = "# BAD TEST " + test_type;
// "{\"error\": \"unknown test type\"," +
// "\"test_type\":" + test_type + "," +
Expand All @@ -134,7 +121,6 @@ int main(int argc, const char** argv)

cout << outputLine << endl;
}

}

return 0;
Expand Down

0 comments on commit 69aa913

Please sign in to comment.