DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (98275c66e600)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "gtest/gtest.h"
#include "nsCollationCID.h"
#include "nsComponentManagerUtils.h"
#include "nsCOMPtr.h"
#include "nsICollation.h"
#include "nsString.h"
#include "nsTArray.h"

TEST(Collation, AllocateRowSortKey)
{
  nsCOMPtr<nsICollationFactory> colFactory =
      do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID);
  ASSERT_TRUE(colFactory);

  // Don't throw error even if locale name is invalid
  nsCOMPtr<nsICollation> collator;
  nsresult rv = colFactory->CreateCollationForLocale(
      NS_LITERAL_CSTRING("$languageName"), getter_AddRefs(collator));
  ASSERT_TRUE(NS_SUCCEEDED(rv));

  nsTArray<uint8_t> sortKey1;
  // Don't throw error even if locale name is invalid
  rv = collator->AllocateRawSortKey(nsICollation::kCollationStrengthDefault,
                                    NS_LITERAL_STRING("ABC"), sortKey1);
  ASSERT_TRUE(NS_SUCCEEDED(rv));

  nsTArray<uint8_t> sortKey2;
  // Don't throw error even if locale name is invalid
  rv = collator->AllocateRawSortKey(nsICollation::kCollationStrengthDefault,
                                    NS_LITERAL_STRING("DEF"), sortKey2);
  ASSERT_TRUE(NS_SUCCEEDED(rv));

  int32_t result;
  rv = collator->CompareRawSortKey(sortKey1, sortKey2, &result);
  ASSERT_TRUE(NS_SUCCEEDED(rv));

  ASSERT_TRUE(result < 0);
}