osquery-1/osquery/core/conversions_tests.cpp
Mitchell Grenier 41283223af Better extended attributes
For the second time in a couple of weeks, I've rewritten the xattr table into
a new extended_attributes table.

If we find an attribute that we don't have a parser for, we will check if it
contains non printable characters. If it does, we'll base64 it. If it doesn't,
we will just output the unencoded string.
2015-04-10 13:17:22 -07:00

60 lines
1.5 KiB
C++

/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <gtest/gtest.h>
#include "osquery/core/conversions.h"
namespace osquery {
class ConversionsTests : public testing::Test {};
class Foobar {};
TEST_F(ConversionsTests, test_conversion) {
boost::shared_ptr<Foobar> b1 = boost::make_shared<Foobar>();
std::shared_ptr<Foobar> s1 = boost_to_std_shared_ptr(b1);
EXPECT_EQ(s1.get(), b1.get());
std::shared_ptr<Foobar> s2 = std::make_shared<Foobar>();
boost::shared_ptr<Foobar> b2 = std_to_boost_shared_ptr(s2);
EXPECT_EQ(s2.get(), b2.get());
}
TEST_F(ConversionsTests, test_base64) {
std::string unencoded = "HELLO";
auto encoded = base64Encode(unencoded);
EXPECT_NE(encoded.size(), 0);
auto unencoded2 = base64Decode(encoded);
EXPECT_EQ(unencoded, unencoded2);
}
TEST_F(ConversionsTests, test_ascii_true) {
std::string unencoded = "HELLO";
auto result = isPrintable(unencoded);
EXPECT_TRUE(result);
}
TEST_F(ConversionsTests, test_ascii_false) {
std::string unencoded = "こんにちは";
auto result = isPrintable(unencoded);
EXPECT_FALSE(result);
}
}
int main(int argc, char* argv[]) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}