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.compare((const char *)backBackBuff) == 0)
63 Ensure(base64, errorsHandling) {
64 string str = "ABC123Test Lets Try this' input and see What \"happens\"";
65 auto *buf = (unsigned char *)malloc(str.length() * 2);
66 auto length = (long)(str.length());
67 assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == -1);
68 length = (long)(str.length() * 2);
69 assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), buf, length) == 0);
70 auto *backBackBuff = (unsigned char *)malloc(length);
71 auto length2 = length >> 2;
72 assert_that(base64::decode(buf, length, backBackBuff, length2) == -1);
73 //std::string str1( backBackBuff, backBackBuff + sizeof backBackBuff / sizeof backBackBuff[0]);
75 assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
76 // assert_that(base64::encode((unsigned char *)str.c_str(), str.length(), nullptr , length) == -1);
77 assert_that(base64::encode(nullptr, str.length(), backBackBuff , length) == -1);
78 assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
79 assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
81 assert_that(base64::encode((unsigned char *)str.c_str(), length1, backBackBuff , length) == -1);
82 assert_that(base64::encode(nullptr, str.length(), backBackBuff , length1) == -1);
87 int main(const int argc, char **argv) {
88 mdclog_severity_t loglevel = MDCLOG_INFO;
90 mdclog_level_set(loglevel);
92 //TestSuite *suite = create_test_suite();
93 TestSuite *suite = create_named_test_suite_(__FUNCTION__, __FILE__, __LINE__);
95 add_test_with_context(suite, base64, encDec);
96 add_test_with_context(suite, base64, errorsHandling);
98 return cgreen::run_test_suite(suite, create_text_reporter());