David Ghandehari | 9e5b587 | 2016-07-28 09:50:04 -0700 | [diff] [blame] | 1 | // 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 | |
| 22 | namespace starboard { |
| 23 | namespace nplb { |
| 24 | namespace { |
| 25 | |
| 26 | const char kSorted[] = "abcdefghijklmnopqrstuvwxyz"; |
| 27 | |
| 28 | int 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 | |
| 34 | TEST(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 |