GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage/nodes/benchmark/out/../test/cctest/test_base64.cc Lines: 53 53 100.0 %
Date: 2019-01-07 12:15:22 Branches: 8 16 50.0 %

Line Branch Exec Source
1
#include "base64.h"
2
3
#include <stddef.h>
4
#include <string.h>
5
6
#include "gtest/gtest.h"
7
8
using node::base64_encode;
9
using node::base64_decode;
10
11
5
TEST(Base64Test, Encode) {
12
7
  auto test = [](const char* string, const char* base64_string) {
13
7
    const size_t len = strlen(base64_string);
14
7
    char* const buffer = new char[len + 1];
15
7
    buffer[len] = 0;
16
7
    base64_encode(string, strlen(string), buffer, len);
17
7
    EXPECT_STREQ(base64_string, buffer);
18
7
    delete[] buffer;
19
7
  };
20
21
1
  test("a", "YQ==");
22
1
  test("ab", "YWI=");
23
1
  test("abc", "YWJj");
24
1
  test("abcd", "YWJjZA==");
25
1
  test("abcde", "YWJjZGU=");
26
1
  test("abcdef", "YWJjZGVm");
27
28
  test("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do "
29
       "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut "
30
       "enim ad minim veniam, quis nostrud exercitation ullamco laboris "
31
       "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in "
32
       "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
33
       "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
34
       "culpa qui officia deserunt mollit anim id est laborum.",
35
36
       "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2Npbmcg"
37
       "ZWxpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0"
38
       "IGRvbG9yZSBtYWduYSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlz"
39
       "IG5vc3RydWQgZXhlcmNpdGF0aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1"
40
       "aXAgZXggZWEgY29tbW9kbyBjb25zZXF1YXQuIER1aXMgYXV0ZSBpcnVyZSBkb2xvciBp"
41
       "biByZXByZWhlbmRlcml0IGluIHZvbHVwdGF0ZSB2ZWxpdCBlc3NlIGNpbGx1bSBkb2xv"
42
       "cmUgZXUgZnVnaWF0IG51bGxhIHBhcmlhdHVyLiBFeGNlcHRldXIgc2ludCBvY2NhZWNh"
43
       "dCBjdXBpZGF0YXQgbm9uIHByb2lkZW50LCBzdW50IGluIGN1bHBhIHF1aSBvZmZpY2lh"
44
1
       "IGRlc2VydW50IG1vbGxpdCBhbmltIGlkIGVzdCBsYWJvcnVtLg==");
45
1
}
46
47
5
TEST(Base64Test, Decode) {
48
25
  auto test = [](const char* base64_string, const char* string) {
49
25
    const size_t len = strlen(string);
50
25
    char* const buffer = new char[len + 1];
51
25
    buffer[len] = 0;
52
25
    base64_decode(buffer, len, base64_string, strlen(base64_string));
53
25
    EXPECT_STREQ(string, buffer);
54
25
    delete[] buffer;
55
25
  };
56
57
1
  test("YQ", "a");
58
1
  test("Y Q", "a");
59
1
  test("Y Q ", "a");
60
1
  test(" Y Q", "a");
61
1
  test("Y Q==", "a");
62
1
  test("YQ ==", "a");
63
1
  test("YQ == junk", "a");
64
1
  test("YWI", "ab");
65
1
  test("YWI=", "ab");
66
1
  test("YWJj", "abc");
67
1
  test("YWJjZA", "abcd");
68
1
  test("YWJjZA==", "abcd");
69
1
  test("YW Jj ZA ==", "abcd");
70
1
  test("YWJjZGU=", "abcde");
71
1
  test("YWJjZGVm", "abcdef");
72
1
  test("Y WJjZGVm", "abcdef");
73
1
  test("YW JjZGVm", "abcdef");
74
1
  test("YWJ jZGVm", "abcdef");
75
1
  test("YWJj ZGVm", "abcdef");
76
1
  test("Y W J j Z G V m", "abcdef");
77
1
  test("Y   W\n JjZ \nG Vm", "abcdef");
78
79
  const char* text =
80
      "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do "
81
      "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut "
82
      "enim ad minim veniam, quis nostrud exercitation ullamco laboris "
83
      "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in "
84
      "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
85
      "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
86
1
      "culpa qui officia deserunt mollit anim id est laborum.";
87
88
  test("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2Npbmcg"
89
       "ZWxpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0"
90
       "IGRvbG9yZSBtYWduYSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlz"
91
       "IG5vc3RydWQgZXhlcmNpdGF0aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1"
92
       "aXAgZXggZWEgY29tbW9kbyBjb25zZXF1YXQuIER1aXMgYXV0ZSBpcnVyZSBkb2xvciBp"
93
       "biByZXByZWhlbmRlcml0IGluIHZvbHVwdGF0ZSB2ZWxpdCBlc3NlIGNpbGx1bSBkb2xv"
94
       "cmUgZXUgZnVnaWF0IG51bGxhIHBhcmlhdHVyLiBFeGNlcHRldXIgc2ludCBvY2NhZWNh"
95
       "dCBjdXBpZGF0YXQgbm9uIHByb2lkZW50LCBzdW50IGluIGN1bHBhIHF1aSBvZmZpY2lh"
96
1
       "IGRlc2VydW50IG1vbGxpdCBhbmltIGlkIGVzdCBsYWJvcnVtLg==", text);
97
98
  test("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2Npbmcg"
99
       "ZWxpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0"
100
       "IGRvbG9yZSBtYWduYSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlz"
101
       "IG5vc3RydWQgZXhlcmNpdGF0aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1"
102
       "aXAgZXggZWEgY29tbW9kbyBjb25zZXF1YXQuIER1aXMgYXV0ZSBpcnVyZSBkb2xvciBp"
103
       "biByZXByZWhlbmRlcml0IGluIHZvbHVwdGF0ZSB2ZWxpdCBlc3NlIGNpbGx1bSBkb2xv"
104
       "cmUgZXUgZnVnaWF0IG51bGxhIHBhcmlhdHVyLiBFeGNlcHRldXIgc2ludCBvY2NhZWNh"
105
       "dCBjdXBpZGF0YXQgbm9uIHByb2lkZW50LCBzdW50IGluIGN1bHBhIHF1aSBvZmZpY2lh"
106
1
       "IGRlc2VydW50IG1vbGxpdCBhbmltIGlkIGVzdCBsYWJvcnVtLg", text);
107
108
  test("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2Npbmcg\n"
109
       "ZWxpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0\n"
110
       "IGRvbG9yZSBtYWduYSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlz\n"
111
       "IG5vc3RydWQgZXhlcmNpdGF0aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1\n"
112
       "aXAgZXggZWEgY29tbW9kbyBjb25zZXF1YXQuIER1aXMgYXV0ZSBpcnVyZSBkb2xvciBp\n"
113
       "biByZXByZWhlbmRlcml0IGluIHZvbHVwdGF0ZSB2ZWxpdCBlc3NlIGNpbGx1bSBkb2xv\n"
114
       "cmUgZXUgZnVnaWF0IG51bGxhIHBhcmlhdHVyLiBFeGNlcHRldXIgc2ludCBvY2NhZWNh\n"
115
       "dCBjdXBpZGF0YXQgbm9uIHByb2lkZW50LCBzdW50IGluIGN1bHBhIHF1aSBvZmZpY2lh\n"
116
1
       "IGRlc2VydW50IG1vbGxpdCBhbmltIGlkIGVzdCBsYWJvcnVtLg==", text);
117
118
  test("TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2Npbmcg\n"
119
       "ZWxpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0\n"
120
       "IGRvbG9yZSBtYWduYSBhbGlxdWEuIFV0IGVuaW0gYWQgbWluaW0gdmVuaWFtLCBxdWlz\n"
121
       "IG5vc3RydWQgZXhlcmNpdGF0aW9uIHVsbGFtY28gbGFib3JpcyBuaXNpIHV0IGFsaXF1\n"
122
       "aXAgZXggZWEgY29tbW9kbyBjb25zZXF1YXQuIER1aXMgYXV0ZSBpcnVyZSBkb2xvciBp\n"
123
       "biByZXByZWhlbmRlcml0IGluIHZvbHVwdGF0ZSB2ZWxpdCBlc3NlIGNpbGx1bSBkb2xv\n"
124
       "cmUgZXUgZnVnaWF0IG51bGxhIHBhcmlhdHVyLiBFeGNlcHRldXIgc2ludCBvY2NhZWNh\n"
125
       "dCBjdXBpZGF0YXQgbm9uIHByb2lkZW50LCBzdW50IGluIGN1bHBhIHF1aSBvZmZpY2lh\n"
126
1
       "IGRlc2VydW50IG1vbGxpdCBhbmltIGlkIGVzdCBsYWJvcnVtLg", text);
127

4
}