blob: 336fb35bd6d1974962a4915c78488bea75b00396 [file] [log] [blame]
Frank Tang3e05d9d2021-11-08 14:04:04 -08001/*
2***********************************************************************
3* © 2020 and later: Unicode, Inc. and others.
4* License & terms of use: http://www.unicode.org/copyright.html
5***********************************************************************
6*/
7
8#include <algorithm>
9#include <vector>
10#include <string>
11
12#include "unicode/locid.h"
13#include "unicode/uperf.h"
14
15//
16// Test case ...
17//
18class LocaleCreateCanonical : public UPerfFunction {
19public:
20 LocaleCreateCanonical() {
21 testCases.push_back("en");
22 testCases.push_back("en-US");
23 testCases.push_back("ja-JP");
24 testCases.push_back("zh-Hant-CN");
25 testCases.push_back("hy-SU");
26 }
27 ~LocaleCreateCanonical() { }
28 virtual void call(UErrorCode* /* status */)
29 {
30 std::for_each(testCases.begin(), testCases.end(),
31 [](const std::string& s)
32 {
33 Locale l = Locale::createCanonical(s.c_str());
34 });
35 }
36 virtual long getOperationsPerIteration() { return testCases.size(); }
37 virtual long getEventsPerIteration() { return testCases.size(); }
38private:
39 std::vector<std::string> testCases;
40};
41
42class LocaleCanonicalizationPerfTest : public UPerfTest
43{
44public:
45 LocaleCanonicalizationPerfTest(
46 int32_t argc, const char *argv[], UErrorCode &status)
47 : UPerfTest(argc, argv, nullptr, 0, "localecanperf", status)
48 {
49 }
50
51 ~LocaleCanonicalizationPerfTest()
52 {
53 }
54 virtual UPerfFunction* runIndexedTest(
55 int32_t index, UBool exec, const char *&name, char *par = nullptr);
56
57private:
58 UPerfFunction* TestLocaleCreateCanonical()
59 {
60 return new LocaleCreateCanonical();
61 }
62};
63
64UPerfFunction*
65LocaleCanonicalizationPerfTest::runIndexedTest(
66 int32_t index, UBool exec, const char *&name, char *par /*= nullptr*/)
67{
68 (void)par;
69 TESTCASE_AUTO_BEGIN;
70
71 TESTCASE_AUTO(TestLocaleCreateCanonical);
72
73 TESTCASE_AUTO_END;
74 return nullptr;
75}
76
77int main(int argc, const char *argv[])
78{
79 UErrorCode status = U_ZERO_ERROR;
80 LocaleCanonicalizationPerfTest test(argc, argv, status);
81
82 if (U_FAILURE(status)){
83 fprintf(stderr, "The error is %s\n", u_errorName(status));
84 test.usage();
85 return status;
86 }
87
Frank Tang1f164ee2022-11-08 12:31:27 -080088 if (test.run() == false){
Frank Tang3e05d9d2021-11-08 14:04:04 -080089 test.usage();
90 fprintf(stderr, "FAILED: Tests could not be run please check the arguments.\n");
91 return -1;
92 }
93 return 0;
94}