Tests: fix up alias and implement first tests
parent
d37f5581c3
commit
12b4a8bb55
|
@ -20,7 +20,12 @@ PROJECT_BASE_DIR="$( cd -- "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 ; pw
|
|||
alias clean="pushd \"$PROJECT_BASE_DIR\" >/dev/null 2>&1; scripts/clean.sh; popd >/dev/null 2>&1"
|
||||
alias clean_dependencies="pushd \"$PROJECT_BASE_DIR\" >/dev/null 2>&1; scripts/clean_dependencies.sh; popd >/dev/null 2>&1"
|
||||
alias setup_project="pushd \"$PROJECT_BASE_DIR\" >/dev/null 2>&1; scripts/setup_project.sh; popd >/dev/null 2>&1"
|
||||
alias run_tests="pushd \"$PROJECT_BASE_DIR\" >/dev/null 2>&1; scripts/test.sh; popd >/dev/null 2>&1"
|
||||
|
||||
function run_tests {
|
||||
pushd "$PROJECT_BASE_DIR" >/dev/null 2>&1
|
||||
scripts/test.sh
|
||||
popd >/dev/null 2>&1
|
||||
}
|
||||
|
||||
function build {
|
||||
pushd "$PROJECT_BASE_DIR" >/dev/null 2>&1
|
||||
|
|
|
@ -1,3 +1,123 @@
|
|||
// Copyright 2022, FOSS-VG Developers and Contributers
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Affero General Public License as published
|
||||
// by the Free Software Foundation, version 3.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied
|
||||
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
// See the GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// version 3 along with this program.
|
||||
// If not, see https://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
|
||||
#include "assert.h++"
|
||||
|
||||
#include "../lib/nbt.h++"
|
||||
#include "../lib/error.h++"
|
||||
|
||||
int main(){
|
||||
|
||||
// used for all integer tests
|
||||
uint8_t data[] = {30, 31, 32, 33, 34, 35, 36, 37, 38, 39};
|
||||
uint64_t dataSize = 10;
|
||||
|
||||
// int8 ############################################################
|
||||
// read successfully
|
||||
uint64_t currentPosition = 5;
|
||||
ASSERT(NBT::helper::readInt8(data, dataSize, currentPosition).value == 35);
|
||||
ASSERT(NBT::helper::readInt8(data, dataSize, currentPosition).isError == false);
|
||||
// begin of data
|
||||
currentPosition = 0;
|
||||
ASSERT(NBT::helper::readInt8(data, dataSize, currentPosition).value == 30);
|
||||
ASSERT(NBT::helper::readInt8(data, dataSize, currentPosition).isError == false);
|
||||
// end of data
|
||||
currentPosition = 9;
|
||||
ASSERT(NBT::helper::readInt8(data, dataSize, currentPosition).value == 39);
|
||||
ASSERT(NBT::helper::readInt8(data, dataSize, currentPosition).isError == false);
|
||||
// out of bounds
|
||||
currentPosition = 10;
|
||||
ASSERT(NBT::helper::readInt8(data, dataSize, currentPosition).isError == true);
|
||||
ASSERT(NBT::helper::readInt8(data, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR);
|
||||
|
||||
std::cout << "Passed readInt8 NBT helper test" << std::endl;
|
||||
|
||||
// int16 ###########################################################
|
||||
// read successfully
|
||||
currentPosition = 5;
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).value == 8996);
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).isError == false);
|
||||
// begin of data
|
||||
currentPosition = 0;
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).value == 7711);
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).isError == false);
|
||||
// end of data
|
||||
currentPosition = 8;
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).value == 9767);
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).isError == false);
|
||||
// partially out of bounds
|
||||
currentPosition = 9;
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).isError == true);
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR);
|
||||
// fully out of bounds
|
||||
currentPosition = 10;
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).isError == true);
|
||||
ASSERT(NBT::helper::readInt16(data, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR);
|
||||
|
||||
std::cout << "Passed readInt16 NBT helper test" << std::endl;
|
||||
|
||||
// int32 ###########################################################
|
||||
// read successfully
|
||||
currentPosition = 5;
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).value == 589571366);
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).isError == false);
|
||||
// begin of data
|
||||
currentPosition = 0;
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).value == 505356321);
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).isError == false);
|
||||
// end of data
|
||||
currentPosition = 6;
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).value == 606414375);
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).isError == false);
|
||||
// partially out of bounds
|
||||
currentPosition = 7;
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).isError == true);
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR);
|
||||
// fully out of bounds
|
||||
currentPosition = 10;
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).isError == true);
|
||||
ASSERT(NBT::helper::readInt32(data, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR);
|
||||
|
||||
std::cout << "Passed readInt32 NBT helper test" << std::endl;
|
||||
|
||||
// int64 ###########################################################
|
||||
// read successfully
|
||||
currentPosition = 1;
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).value == 2242829044932683046L);
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).isError == false);
|
||||
// begin of data
|
||||
currentPosition = 0;
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).value == 2170488872094606374L);
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).isError == false);
|
||||
// end of data
|
||||
currentPosition = 2;
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).value == 2315169217770759719L);
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).isError == false);
|
||||
// partially out of bounds
|
||||
currentPosition = 3;
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).isError == true);
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR);
|
||||
// fully out of bounds
|
||||
currentPosition = 10;
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).isError == true);
|
||||
ASSERT(NBT::helper::readInt64(data, dataSize, currentPosition).errorCode == ErrorCodes::RANGE_ERROR);
|
||||
|
||||
std::cout << "Passed int64 NBT helper test" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue