/src/mozilla-central/intl/locale/tests/gtest/TestCollation.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "gtest/gtest.h" |
7 | | #include "mozilla/Services.h" |
8 | | #include "nsCollationCID.h" |
9 | | #include "nsComponentManagerUtils.h" |
10 | | #include "nsCOMPtr.h" |
11 | | #include "nsICollation.h" |
12 | | #include "nsString.h" |
13 | | |
14 | 0 | TEST(Collation, AllocateRowSortKey) { |
15 | 0 | nsCOMPtr<nsICollationFactory> colFactory = |
16 | 0 | do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID); |
17 | 0 | ASSERT_TRUE(colFactory); |
18 | 0 |
|
19 | 0 | // Don't throw error even if locale name is invalid |
20 | 0 | nsCOMPtr<nsICollation> collator; |
21 | 0 | nsresult rv = |
22 | 0 | colFactory->CreateCollationForLocale(NS_LITERAL_CSTRING("$languageName"), |
23 | 0 | getter_AddRefs(collator)); |
24 | 0 | ASSERT_TRUE(NS_SUCCEEDED(rv)); |
25 | 0 |
|
26 | 0 | uint8_t* sortKey1 = nullptr; |
27 | 0 | uint32_t sortKeyLen1 = 0; |
28 | 0 | // Don't throw error even if locale name is invalid |
29 | 0 | rv = collator->AllocateRawSortKey(nsICollation::kCollationStrengthDefault, |
30 | 0 | NS_LITERAL_STRING("ABC"), |
31 | 0 | &sortKey1, &sortKeyLen1); |
32 | 0 | ASSERT_TRUE(NS_SUCCEEDED(rv)); |
33 | 0 |
|
34 | 0 | uint8_t* sortKey2 = nullptr; |
35 | 0 | uint32_t sortKeyLen2 = 0; |
36 | 0 | // Don't throw error even if locale name is invalid |
37 | 0 | rv = collator->AllocateRawSortKey(nsICollation::kCollationStrengthDefault, |
38 | 0 | NS_LITERAL_STRING("DEF"), |
39 | 0 | &sortKey2, &sortKeyLen2); |
40 | 0 | ASSERT_TRUE(NS_SUCCEEDED(rv)); |
41 | 0 |
|
42 | 0 | int32_t result; |
43 | 0 | rv = collator->CompareRawSortKey(sortKey1, sortKeyLen1, |
44 | 0 | sortKey2, sortKeyLen2, &result); |
45 | 0 | ASSERT_TRUE(NS_SUCCEEDED(rv)); |
46 | 0 |
|
47 | 0 | ASSERT_TRUE(result < 0); |
48 | 0 |
|
49 | 0 | free(sortKey1); |
50 | 0 | free(sortKey2); |
51 | 0 | } |