2 * Copyright 2019 AT&T Intellectual Property
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 // Created by adi ENZEL on 11/27/19.
23 #include <mdclog/mdclog.h>
24 #include <cgreen/cgreen.h>
36 using namespace cgreen;
40 mdclog_attr_init(&attr);
41 mdclog_attr_set_ident(attr, "TestConfiguration");
43 mdclog_attr_destroy(attr);
46 const char *data = "ABC123Test Lets Try this' input and see What \"happens\"";
48 Ensure(base64, encDec) {
49 string str = "ABC123Test Lets Try this' input and see What \"happens\"";
50 auto *buf = (unsigned char *)malloc(str.length() * 2);
51 auto length = (long)(str.length() * 2);
52 base64::encode((unsigned char *)str.c_str(), str.length(), buf, length);
53 auto *backBackBuff = (unsigned char *)malloc(length);
54 auto length2 = length;
55 assert_that(base64::decode(buf, length, backBackBuff, length2) == 0);
56 std::string str1( backBackBuff, backBackBuff + sizeof backBackBuff / sizeof backBackBuff[0]);
58 assert_that(str.length() == (ulong)length2)
59 //auto val = str.compare((const char *)backBackBuff);
60 assert_that(str.compare((const char *)backBackBuff) == 0)
65 Ensure(base64, errorsHandling) {
66 string str = "ABC123Test Lets Try this' input and see What \"happens\"";
67 auto *buf = (unsigned char *)malloc(str.length() * 2);
68 auto length = (long)(str.length());
69 assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == -1);
70 length = (long)(str.length() * 2);
71 assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == 0);
72 auto *backBackBuff = (unsigned char *)malloc(length);
73 auto length2 = length >> 2;
74 assert_that(base64::decode(buf, length, backBackBuff, length2) == -1);
75 //std::string str1( backBackBuff, backBackBuff + sizeof backBackBuff / sizeof backBackBuff[0]);
77 assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
78 // assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
79 assert_that(base64::encode(nullptr, str.length(), backBackBuff , length) == -1);
80 assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
81 assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
83 assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
84 assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
89 int main(const int argc, char **argv) {
90 mdclog_severity_t loglevel = MDCLOG_INFO;
92 mdclog_level_set(loglevel);
94 //TestSuite *suite = create_test_suite();
95 TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
97 add_test_with_context(suite, base64, encDec);
98 add_test_with_context(suite, base64, errorsHandling);
100 return cgreen::run_test_suite(suite, create_text_reporter());