1 /*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #define LOG_TAG "RdbNdkPredicatesPrefTest"
16 #include <gtest/gtest.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19
20 #include <string>
21
22 #include "logger.h"
23 #include "relational_store.h"
24 using namespace testing::ext;
25 using namespace OHOS::Rdb;
26 class RdbNdkPredicatesPrefTest : public testing::Test {
27 public:
28 static void SetUpTestCase(void);
29 static void TearDownTestCase(void);
30 void SetUp();
31 void TearDown();
32 };
33 const int BASE_COUNT = 2000;
34 const int HAVING_BASE_LINE = 10;
SetUpTestCase(void)35 void RdbNdkPredicatesPrefTest::SetUpTestCase(void)
36 {
37 }
38
TearDownTestCase(void)39 void RdbNdkPredicatesPrefTest::TearDownTestCase(void)
40 {
41 }
42
SetUp(void)43 void RdbNdkPredicatesPrefTest::SetUp(void)
44 {
45 }
46
TearDown(void)47 void RdbNdkPredicatesPrefTest::TearDown(void)
48 {
49 }
50
51 /**
52 * @tc.name: RDB_predicates_pref_test_having
53 * @tc.desc: Performance testing of basic scenarios for the Having interface
54 * @tc.type: FUNC
55 */
56 HWTEST_F(RdbNdkPredicatesPrefTest, RDB_predicates_pref_test_having, TestSize.Level1)
57 {
58 OH_Predicates *predicates = OH_Rdb_CreatePredicates("test");
59 const char *columnNames[] = { "data"};
60 predicates->groupBy(predicates, columnNames, 1);
61 auto start = std::chrono::high_resolution_clock::now();
62 for (int i = 0; i < BASE_COUNT; i++) {
63 OH_Predicates_Having(predicates, "data", nullptr);
64 }
65 auto end = std::chrono::high_resolution_clock::now();
66 auto total = std::chrono::duration_cast<std::chrono::microseconds>(end - start).count();
67 double averageTime = static_cast<double>(total) / BASE_COUNT;
68 LOG_INFO("the predicates_pref_test_having average time is %{public}f", averageTime);
69 ASSERT_TRUE(averageTime < HAVING_BASE_LINE);
70 }