blob: 6c17806da538545133f5ee8fddf01fdca783fae7 [file] [log] [blame]
David Ghandehari9e5b5872016-07-28 09:50:04 -07001// Copyright 2016 Google Inc. All Rights Reserved.
2//
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// Here we are not trying to do anything fancy, just to really sanity check that
16// this is hooked up to something.
17
18#include "starboard/string.h"
19#include "starboard/system.h"
20#include "testing/gtest/include/gtest/gtest.h"
21
22namespace starboard {
23namespace nplb {
24namespace {
25
26const char kSorted[] = "abcdefghijklmnopqrstuvwxyz";
27
28int CharComparator(const void* a, const void* b) {
29 const char* ac = reinterpret_cast<const char*>(a);
30 const char* bc = reinterpret_cast<const char*>(b);
31 return *ac - *bc;
32}
33
34TEST(SbSystemBinarySearchTest, SunnyDayLetters) {
35 char buf[SB_ARRAY_SIZE(kSorted)] = {0};
36 SbStringCopy(buf, kSorted, SB_ARRAY_SIZE(buf));
37 void* result = SbSystemBinarySearch("k", kSorted, SB_ARRAY_SIZE(kSorted) - 1,
38 1, CharComparator);
39 EXPECT_EQ(result, kSorted + ('k' - 'a'));
40}
41
42} // namespace
43} // namespace nplb
44} // namespace starboard