Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/media/gmp-clearkey/0.1/gtest/TestClearKeyUtils.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 <algorithm>
9
#include <stdint.h>
10
#include <vector>
11
12
#include "../ClearKeyBase64.cpp"
13
14
using namespace std;
15
16
struct B64Test {
17
  string b64;
18
  vector<uint8_t> raw;
19
  bool shouldPass;
20
};
21
22
const B64Test tests[] = {
23
  {
24
    "AAAAADk4AU4AAAAAAAAAAA",
25
    { 0x0, 0x0, 0x0, 0x0, 0x39, 0x38, 0x1, 0x4e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 },
26
    true
27
  },
28
  {
29
    "h2mqp1zAJjDIC34YXEXBxA==",
30
    { 0x87, 0x69, 0xaa, 0xa7, 0x5c, 0xc0, 0x26, 0x30, 0xc8, 0xb, 0x7e, 0x18, 0x5c, 0x45, 0xc1, 0xc4 },
31
    true
32
  },
33
  {
34
    "flcdA35XHQN-Vx0DflcdAw",
35
    { 0x7e, 0x57, 0x1d, 0x3, 0x7e, 0x57, 0x1d, 0x3, 0x7e, 0x57, 0x1d, 0x3, 0x7e, 0x57, 0x1d, 0x3 },
36
    true
37
  },
38
  {
39
    "flczM35XMzN-VzMzflczMw",
40
    { 0x7e, 0x57, 0x33, 0x33, 0x7e, 0x57, 0x33, 0x33, 0x7e, 0x57, 0x33, 0x33, 0x7e, 0x57, 0x33, 0x33 },
41
    true,
42
  },
43
  {
44
    "flcdBH5XHQR-Vx0EflcdBA",
45
    { 0x7e, 0x57, 0x1d, 0x4, 0x7e, 0x57, 0x1d, 0x4, 0x7e, 0x57, 0x1d, 0x4, 0x7e, 0x57, 0x1d, 0x4 },
46
    true
47
  },
48
  {
49
    "fldERH5XRER-V0REfldERA",
50
    { 0x7e, 0x57, 0x44, 0x44, 0x7e, 0x57, 0x44, 0x44, 0x7e, 0x57, 0x44, 0x44, 0x7e, 0x57, 0x44, 0x44 },
51
    true
52
  },
53
  {
54
    "fuzzbiz=",
55
    { 0x7e, 0xec, 0xf3, 0x6e, 0x2c },
56
    true
57
  },
58
  {
59
    "fuzzbizfuzzbizfuzzbizfuzzbizfuzzbizfuzzbizfuzzbizfuzzbiz",
60
    {
61
      0x7e, 0xec, 0xf3, 0x6e, 0x2c, 0xdf, 0xbb, 0x3c, 0xdb, 0x8b,
62
      0x37, 0xee, 0xcf, 0x36, 0xe2, 0xcd, 0xfb, 0xb3, 0xcd, 0xb8,
63
      0xb3, 0x7e, 0xec, 0xf3, 0x6e, 0x2c, 0xdf, 0xbb, 0x3c, 0xdb,
64
      0x8b, 0x37, 0xee, 0xcf, 0x36, 0xe2, 0xcd, 0xfb, 0xb3, 0xcd,
65
      0xb8, 0xb3
66
    },
67
    true
68
  },
69
  { "", { }, true },
70
  { "00", { 0xd3 }, true },
71
  { "000", { 0xd3, 0x4d }, true },
72
73
  { "invalid", { 0x8a, 0x7b, 0xda, 0x96, 0x27 }, true },
74
  { "invalic", { 0x8a, 0x7b, 0xda, 0x96, 0x27 }, true },
75
76
  // Failure tests
77
  { "A", { }, false }, // 1 character is too few.
78
  { "_", { }, false }, // 1 character is too few.
79
};
80
81
0
TEST(ClearKey, DecodeBase64) {
82
0
  for (const B64Test& test : tests) {
83
0
    vector<uint8_t> v;
84
0
    bool rv = DecodeBase64(string(test.b64), v);
85
0
    EXPECT_EQ(test.shouldPass, rv);
86
0
    if (test.shouldPass) {
87
0
      EXPECT_EQ(test.raw.size(), v.size());
88
0
      for (size_t k = 0; k < test.raw.size(); k++) {
89
0
        EXPECT_EQ(test.raw[k], v[k]);
90
0
      }
91
0
    }
92
0
  }
93
0
}