/src/mozilla-central/dom/media/gtest/TestGMPUtils.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #include "gtest/gtest.h" |
8 | | #include "GMPUtils.h" |
9 | | #include "nsString.h" |
10 | | |
11 | | #include <string> |
12 | | #include <vector> |
13 | | |
14 | | using namespace std; |
15 | | using namespace mozilla; |
16 | | |
17 | | void TestSplitAt(const char* aInput, |
18 | | const char* aDelims, |
19 | | size_t aNumExpectedTokens, |
20 | | const char* aExpectedTokens[]) |
21 | 0 | { |
22 | 0 | nsCString input(aInput); |
23 | 0 | nsTArray<nsCString> tokens; |
24 | 0 | SplitAt(aDelims, input, tokens); |
25 | 0 | EXPECT_EQ(tokens.Length(), aNumExpectedTokens) << "Should get expected number of tokens"; |
26 | 0 | for (size_t i = 0; i < tokens.Length(); i++) { |
27 | 0 | EXPECT_TRUE(tokens[i].EqualsASCII(aExpectedTokens[i])) |
28 | 0 | << "Tokenize fail; expected=" << aExpectedTokens[i] << " got=" << |
29 | 0 | tokens[i].BeginReading(); |
30 | 0 | } |
31 | 0 | } |
32 | | |
33 | 0 | TEST(GeckoMediaPlugins, TestSplitAt) { |
34 | 0 | { |
35 | 0 | const char* input = "1,2,3,4"; |
36 | 0 | const char* delims = ","; |
37 | 0 | const char* tokens[] = { "1", "2", "3", "4" }; |
38 | 0 | TestSplitAt(input, delims, MOZ_ARRAY_LENGTH(tokens), tokens); |
39 | 0 | } |
40 | 0 |
|
41 | 0 | { |
42 | 0 | const char* input = "a simple, comma, seperated, list"; |
43 | 0 | const char* delims = ","; |
44 | 0 | const char* tokens[] = { "a simple", " comma", " seperated", " list" }; |
45 | 0 | TestSplitAt(input, delims, MOZ_ARRAY_LENGTH(tokens), tokens); |
46 | 0 | } |
47 | 0 |
|
48 | 0 | { |
49 | 0 | const char* input = // Various platform line endings... |
50 | 0 | "line1\r\n" // Windows |
51 | 0 | "line2\r" // Old MacOSX |
52 | 0 | "line3\n" // Unix |
53 | 0 | "line4"; |
54 | 0 | const char* delims = "\r\n"; |
55 | 0 | const char* tokens[] = { "line1", "line2", "line3", "line4" }; |
56 | 0 | TestSplitAt(input, delims, MOZ_ARRAY_LENGTH(tokens), tokens); |
57 | 0 | } |
58 | 0 | } |
59 | | |
60 | 0 | TEST(GeckoMediaPlugins, ToHexString) { |
61 | 0 | struct Test { |
62 | 0 | nsTArray<uint8_t> bytes; |
63 | 0 | string hex; |
64 | 0 | }; |
65 | 0 |
|
66 | 0 | static const Test tests[] = { |
67 | 0 | { {0x00, 0x00}, "0000" }, |
68 | 0 | { {0xff, 0xff}, "ffff" }, |
69 | 0 | { {0xff, 0x00}, "ff00" }, |
70 | 0 | { {0x00, 0xff}, "00ff" }, |
71 | 0 | { {0xf0, 0x10}, "f010" }, |
72 | 0 | { {0x05, 0x50}, "0550" }, |
73 | 0 | { {0xf}, "0f" }, |
74 | 0 | { {0x10}, "10" }, |
75 | 0 | { {}, "" }, |
76 | 0 | { |
77 | 0 | { |
78 | 0 | 0x00, 0x11, 0x22, 0x33, |
79 | 0 | 0x44, 0x55, 0x66, 0x77, |
80 | 0 | 0x88, 0x99, 0xaa, 0xbb, |
81 | 0 | 0xcc, 0xdd, 0xee, 0xff |
82 | 0 | }, |
83 | 0 | "00112233445566778899aabbccddeeff" |
84 | 0 | }, |
85 | 0 | }; |
86 | 0 |
|
87 | 0 | for (const Test& test : tests) { |
88 | 0 | EXPECT_STREQ(test.hex.c_str(), ToHexString(test.bytes).get()); |
89 | 0 | } |
90 | 0 | } |