mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
Adds new build system to repo (#1)
This commit is contained in:
committed by
Peter Johnson
parent
4f5b5b1377
commit
1243cf04ea
76
src/test/native/cpp/Base64Test.cpp
Normal file
76
src/test/native/cpp/Base64Test.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "support/Base64.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
struct Base64TestParam {
|
||||
int plain_len;
|
||||
const char* plain;
|
||||
const char* encoded;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Base64TestParam& param) {
|
||||
os << "Base64TestParam(Len: " << param.plain_len << ", "
|
||||
<< "Plain: \"" << param.plain << "\", "
|
||||
<< "Encoded: \"" << param.encoded << "\")";
|
||||
return os;
|
||||
}
|
||||
|
||||
class Base64Test : public ::testing::TestWithParam<Base64TestParam> {
|
||||
protected:
|
||||
llvm::StringRef GetPlain() {
|
||||
if (GetParam().plain_len < 0)
|
||||
return llvm::StringRef(GetParam().plain);
|
||||
else
|
||||
return llvm::StringRef(GetParam().plain, GetParam().plain_len);
|
||||
}
|
||||
};
|
||||
|
||||
TEST_P(Base64Test, Encode) {
|
||||
std::string s;
|
||||
Base64Encode(GetPlain(), &s);
|
||||
ASSERT_EQ(GetParam().encoded, s);
|
||||
}
|
||||
|
||||
TEST_P(Base64Test, Decode) {
|
||||
std::string s;
|
||||
llvm::StringRef encoded = GetParam().encoded;
|
||||
EXPECT_EQ(encoded.size(), Base64Decode(encoded, &s));
|
||||
ASSERT_EQ(GetPlain(), s);
|
||||
}
|
||||
|
||||
static Base64TestParam sample[] = {
|
||||
{-1, "Send reinforcements", "U2VuZCByZWluZm9yY2VtZW50cw=="},
|
||||
{-1, "Now is the time for all good coders\n to learn C++",
|
||||
"Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKIHRvIGxlYXJuIEMrKw=="},
|
||||
{-1,
|
||||
"This is line one\nThis is line two\nThis is line three\nAnd so on...\n",
|
||||
"VGhpcyBpcyBsaW5lIG9uZQpUaGlzIGlzIGxpbmUgdHdvClRoaXMgaXMgbGluZSB0aHJlZQpBb"
|
||||
"mQgc28gb24uLi4K"},
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Base64Sample, Base64Test, ::testing::ValuesIn(sample));
|
||||
|
||||
static Base64TestParam standard[] = {
|
||||
{0, "", ""},
|
||||
{1, "\0", "AA=="},
|
||||
{2, "\0\0", "AAA="},
|
||||
{3, "\0\0\0", "AAAA"},
|
||||
{1, "\377", "/w=="},
|
||||
{2, "\377\377", "//8="},
|
||||
{3, "\377\377\377", "////"},
|
||||
{2, "\xff\xef", "/+8="},
|
||||
};
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(Base64Standard, Base64Test,
|
||||
::testing::ValuesIn(standard));
|
||||
|
||||
} // namespace wpi
|
||||
114
src/test/native/cpp/leb128Test.cpp
Normal file
114
src/test/native/cpp/leb128Test.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
//===- llvm/unittest/Support/LEB128Test.cpp - LEB128 function tests -------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "support/leb128.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "llvm/SmallString.h"
|
||||
#include "llvm/StringRef.h"
|
||||
|
||||
#include "support/raw_istream.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
TEST(LEB128Test, WriteUleb128) {
|
||||
#define EXPECT_ULEB128_EQ(EXPECTED, VALUE, PAD) \
|
||||
do { \
|
||||
llvm::StringRef expected(EXPECTED, sizeof(EXPECTED)-1); \
|
||||
llvm::SmallString<32> buf; \
|
||||
std::size_t size = WriteUleb128(buf, VALUE); \
|
||||
EXPECT_EQ(size, buf.size()); \
|
||||
EXPECT_EQ(expected, buf.str()); \
|
||||
} while (0)
|
||||
|
||||
// Write ULEB128
|
||||
EXPECT_ULEB128_EQ("\x00", 0, 0);
|
||||
EXPECT_ULEB128_EQ("\x01", 1, 0);
|
||||
EXPECT_ULEB128_EQ("\x3f", 63, 0);
|
||||
EXPECT_ULEB128_EQ("\x40", 64, 0);
|
||||
EXPECT_ULEB128_EQ("\x7f", 0x7f, 0);
|
||||
EXPECT_ULEB128_EQ("\x80\x01", 0x80, 0);
|
||||
EXPECT_ULEB128_EQ("\x81\x01", 0x81, 0);
|
||||
EXPECT_ULEB128_EQ("\x90\x01", 0x90, 0);
|
||||
EXPECT_ULEB128_EQ("\xff\x01", 0xff, 0);
|
||||
EXPECT_ULEB128_EQ("\x80\x02", 0x100, 0);
|
||||
EXPECT_ULEB128_EQ("\x81\x02", 0x101, 0);
|
||||
|
||||
#undef EXPECT_ULEB128_EQ
|
||||
}
|
||||
|
||||
TEST(LEB128Test, ReadUleb128) {
|
||||
#define EXPECT_READ_ULEB128_EQ(EXPECTED, VALUE) \
|
||||
do { \
|
||||
unsigned long val = 0; \
|
||||
std::size_t size = ReadUleb128(VALUE, &val); \
|
||||
EXPECT_EQ(sizeof(VALUE) - 1, size); \
|
||||
EXPECT_EQ(EXPECTED, val); \
|
||||
} while (0)
|
||||
|
||||
// Read ULEB128
|
||||
EXPECT_READ_ULEB128_EQ(0u, "\x00");
|
||||
EXPECT_READ_ULEB128_EQ(1u, "\x01");
|
||||
EXPECT_READ_ULEB128_EQ(63u, "\x3f");
|
||||
EXPECT_READ_ULEB128_EQ(64u, "\x40");
|
||||
EXPECT_READ_ULEB128_EQ(0x7fu, "\x7f");
|
||||
EXPECT_READ_ULEB128_EQ(0x80u, "\x80\x01");
|
||||
EXPECT_READ_ULEB128_EQ(0x81u, "\x81\x01");
|
||||
EXPECT_READ_ULEB128_EQ(0x90u, "\x90\x01");
|
||||
EXPECT_READ_ULEB128_EQ(0xffu, "\xff\x01");
|
||||
EXPECT_READ_ULEB128_EQ(0x100u, "\x80\x02");
|
||||
EXPECT_READ_ULEB128_EQ(0x101u, "\x81\x02");
|
||||
EXPECT_READ_ULEB128_EQ(8320u, "\x80\xc1\x80\x80\x10");
|
||||
|
||||
#undef EXPECT_READ_ULEB128_EQ
|
||||
}
|
||||
|
||||
TEST(LEB128Test, SizeUleb128) {
|
||||
// Testing Plan:
|
||||
// (1) 128 ^ n ............ need (n+1) bytes
|
||||
// (2) 128 ^ n * 64 ....... need (n+1) bytes
|
||||
// (3) 128 ^ (n+1) - 1 .... need (n+1) bytes
|
||||
|
||||
EXPECT_EQ(1u, SizeUleb128(0)); // special case
|
||||
|
||||
EXPECT_EQ(1u, SizeUleb128(0x1UL));
|
||||
EXPECT_EQ(1u, SizeUleb128(0x40UL));
|
||||
EXPECT_EQ(1u, SizeUleb128(0x7fUL));
|
||||
|
||||
EXPECT_EQ(2u, SizeUleb128(0x80UL));
|
||||
EXPECT_EQ(2u, SizeUleb128(0x2000UL));
|
||||
EXPECT_EQ(2u, SizeUleb128(0x3fffUL));
|
||||
|
||||
EXPECT_EQ(3u, SizeUleb128(0x4000UL));
|
||||
EXPECT_EQ(3u, SizeUleb128(0x100000UL));
|
||||
EXPECT_EQ(3u, SizeUleb128(0x1fffffUL));
|
||||
|
||||
EXPECT_EQ(4u, SizeUleb128(0x200000UL));
|
||||
EXPECT_EQ(4u, SizeUleb128(0x8000000UL));
|
||||
EXPECT_EQ(4u, SizeUleb128(0xfffffffUL));
|
||||
|
||||
EXPECT_EQ(5u, SizeUleb128(0x10000000UL));
|
||||
EXPECT_EQ(5u, SizeUleb128(0x40000000UL));
|
||||
EXPECT_EQ(5u, SizeUleb128(0x7fffffffUL));
|
||||
|
||||
EXPECT_EQ(5u, SizeUleb128(UINT32_MAX));
|
||||
}
|
||||
|
||||
} // namespace wpi
|
||||
15
src/test/native/cpp/main.cpp
Normal file
15
src/test/native/cpp/main.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) FIRST 2015. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
int ret = RUN_ALL_TESTS();
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user