2022-07-20 04:51:05 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <memory>
|
2022-11-07 08:12:35 +00:00
|
|
|
#include <gtest/gtest.h>
|
2022-07-20 04:51:05 +00:00
|
|
|
|
|
|
|
#include "AMFDeserialize.h"
|
2023-05-13 22:22:00 +00:00
|
|
|
#include "Amf3.h"
|
|
|
|
|
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* Helper method that all tests use to get their respective AMF.
|
|
|
|
*/
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> ReadFromBitStream(RakNet::BitStream& bitStream) {
|
2022-07-20 04:51:05 +00:00
|
|
|
AMFDeserialize deserializer;
|
2023-05-13 22:22:00 +00:00
|
|
|
AMFBaseValue* returnValue(deserializer.Read(bitStream));
|
2024-02-27 07:29:51 +00:00
|
|
|
return std::unique_ptr<AMFBaseValue>{ returnValue };
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Test reading an AMFUndefined value from a BitStream.
|
|
|
|
*/
|
|
|
|
TEST(dCommonTests, AMFDeserializeAMFUndefinedTest) {
|
2023-05-13 22:22:00 +00:00
|
|
|
CBITSTREAM;
|
2022-08-05 13:40:12 +00:00
|
|
|
bitStream.Write<uint8_t>(0x00);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::Undefined);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Test reading an AMFNull value from a BitStream.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
TEST(dCommonTests, AMFDeserializeAMFNullTest) {
|
2023-05-13 22:22:00 +00:00
|
|
|
CBITSTREAM;
|
2022-08-05 13:40:12 +00:00
|
|
|
bitStream.Write<uint8_t>(0x01);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::Null);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Test reading an AMFFalse value from a BitStream.
|
|
|
|
*/
|
|
|
|
TEST(dCommonTests, AMFDeserializeAMFFalseTest) {
|
2023-05-13 22:22:00 +00:00
|
|
|
CBITSTREAM;
|
2022-08-05 13:40:12 +00:00
|
|
|
bitStream.Write<uint8_t>(0x02);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::False);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Test reading an AMFTrue value from a BitStream.
|
|
|
|
*/
|
|
|
|
TEST(dCommonTests, AMFDeserializeAMFTrueTest) {
|
2023-05-13 22:22:00 +00:00
|
|
|
CBITSTREAM;
|
2022-08-05 13:40:12 +00:00
|
|
|
bitStream.Write<uint8_t>(0x03);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::True);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Test reading an AMFInteger value from a BitStream.
|
|
|
|
*/
|
|
|
|
TEST(dCommonTests, AMFDeserializeAMFIntegerTest) {
|
2023-05-13 22:22:00 +00:00
|
|
|
CBITSTREAM;
|
2022-07-20 04:51:05 +00:00
|
|
|
{
|
|
|
|
bitStream.Write<uint8_t>(0x04);
|
2022-08-05 13:40:12 +00:00
|
|
|
// 127 == 01111111
|
|
|
|
bitStream.Write<uint8_t>(127);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::Integer);
|
2022-08-05 13:40:12 +00:00
|
|
|
// Check that the max value of a byte can be read correctly
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), 127);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
bitStream.Reset();
|
|
|
|
{
|
|
|
|
bitStream.Write<uint8_t>(0x04);
|
|
|
|
bitStream.Write<uint32_t>(UINT32_MAX);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::Integer);
|
2022-07-20 04:51:05 +00:00
|
|
|
// Check that we can read the maximum value correctly
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), 536870911);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
bitStream.Reset();
|
|
|
|
{
|
|
|
|
bitStream.Write<uint8_t>(0x04);
|
|
|
|
// 131 == 10000011
|
|
|
|
bitStream.Write<uint8_t>(131);
|
|
|
|
// 255 == 11111111
|
|
|
|
bitStream.Write<uint8_t>(255);
|
|
|
|
// 127 == 01111111
|
|
|
|
bitStream.Write<uint8_t>(127);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::Integer);
|
2022-07-20 04:51:05 +00:00
|
|
|
// Check that short max can be read correctly
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), UINT16_MAX);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
bitStream.Reset();
|
|
|
|
{
|
|
|
|
bitStream.Write<uint8_t>(0x04);
|
|
|
|
// 255 == 11111111
|
|
|
|
bitStream.Write<uint8_t>(255);
|
|
|
|
// 127 == 01111111
|
|
|
|
bitStream.Write<uint8_t>(127);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::Integer);
|
2022-07-20 04:51:05 +00:00
|
|
|
// Check that 2 byte max can be read correctly
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(static_cast<AMFIntValue*>(res.get())->GetValue(), 16383);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Test reading an AMFDouble value from a BitStream.
|
|
|
|
*/
|
|
|
|
TEST(dCommonTests, AMFDeserializeAMFDoubleTest) {
|
2023-05-13 22:22:00 +00:00
|
|
|
CBITSTREAM;
|
2022-08-05 13:40:12 +00:00
|
|
|
bitStream.Write<uint8_t>(0x05);
|
2022-07-20 04:51:05 +00:00
|
|
|
bitStream.Write<double>(25346.4f);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::Double);
|
|
|
|
ASSERT_EQ(static_cast<AMFDoubleValue*>(res.get())->GetValue(), 25346.4f);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Test reading an AMFString value from a BitStream.
|
|
|
|
*/
|
|
|
|
TEST(dCommonTests, AMFDeserializeAMFStringTest) {
|
2023-05-13 22:22:00 +00:00
|
|
|
CBITSTREAM;
|
2022-08-05 13:40:12 +00:00
|
|
|
bitStream.Write<uint8_t>(0x06);
|
2022-07-20 04:51:05 +00:00
|
|
|
bitStream.Write<uint8_t>(0x0F);
|
|
|
|
std::string toWrite = "stateID";
|
|
|
|
for (auto e : toWrite) bitStream.Write<char>(e);
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::String);
|
|
|
|
ASSERT_EQ(static_cast<AMFStringValue*>(res.get())->GetValue(), "stateID");
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Test reading an AMFArray value from a BitStream.
|
|
|
|
*/
|
|
|
|
TEST(dCommonTests, AMFDeserializeAMFArrayTest) {
|
2023-05-13 22:22:00 +00:00
|
|
|
CBITSTREAM;
|
2022-08-05 13:40:12 +00:00
|
|
|
// Test empty AMFArray
|
|
|
|
bitStream.Write<uint8_t>(0x09);
|
2022-07-20 04:51:05 +00:00
|
|
|
bitStream.Write<uint8_t>(0x01);
|
|
|
|
bitStream.Write<uint8_t>(0x01);
|
|
|
|
{
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::Array);
|
|
|
|
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetAssociative().size(), 0);
|
|
|
|
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetDense().size(), 0);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
bitStream.Reset();
|
2022-07-22 05:26:09 +00:00
|
|
|
// Test a key'd value and dense value
|
2022-07-20 04:51:05 +00:00
|
|
|
bitStream.Write<uint8_t>(0x09);
|
2022-07-22 05:26:09 +00:00
|
|
|
bitStream.Write<uint8_t>(0x03);
|
2022-07-20 04:51:05 +00:00
|
|
|
bitStream.Write<uint8_t>(0x15);
|
|
|
|
for (auto e : "BehaviorID") if (e != '\0') bitStream.Write<char>(e);
|
|
|
|
bitStream.Write<uint8_t>(0x06);
|
|
|
|
bitStream.Write<uint8_t>(0x0B);
|
|
|
|
for (auto e : "10447") if (e != '\0') bitStream.Write<char>(e);
|
|
|
|
bitStream.Write<uint8_t>(0x01);
|
2022-07-22 05:26:09 +00:00
|
|
|
bitStream.Write<uint8_t>(0x06);
|
|
|
|
bitStream.Write<uint8_t>(0x0B);
|
|
|
|
for (auto e : "10447") if (e != '\0') bitStream.Write<char>(e);
|
2022-07-20 04:51:05 +00:00
|
|
|
{
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> res{ ReadFromBitStream(bitStream) };
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(res->GetValueType(), eAmf::Array);
|
|
|
|
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetAssociative().size(), 1);
|
|
|
|
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->GetDense().size(), 1);
|
|
|
|
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->Get<std::string>("BehaviorID")->GetValue(), "10447");
|
|
|
|
ASSERT_EQ(static_cast<AMFArrayValue*>(res.get())->Get<std::string>(0)->GetValue(), "10447");
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-05-13 22:22:00 +00:00
|
|
|
* @brief This test checks that if we recieve an unimplemented eAmf
|
2022-07-20 04:51:05 +00:00
|
|
|
* we correctly throw an error and can actch it.
|
2023-04-12 16:48:20 +00:00
|
|
|
* Yes this leaks memory.
|
2022-07-20 04:51:05 +00:00
|
|
|
*/
|
2022-11-07 08:12:35 +00:00
|
|
|
TEST(dCommonTests, AMFDeserializeUnimplementedValuesTest) {
|
2023-05-13 22:22:00 +00:00
|
|
|
std::vector<eAmf> unimplementedValues = {
|
|
|
|
eAmf::XMLDoc,
|
|
|
|
eAmf::Date,
|
|
|
|
eAmf::Object,
|
|
|
|
eAmf::XML,
|
|
|
|
eAmf::ByteArray,
|
|
|
|
eAmf::VectorInt,
|
|
|
|
eAmf::VectorUInt,
|
|
|
|
eAmf::VectorDouble,
|
|
|
|
eAmf::VectorObject,
|
|
|
|
eAmf::Dictionary
|
2022-07-28 13:39:57 +00:00
|
|
|
};
|
2022-07-20 04:51:05 +00:00
|
|
|
// Run unimplemented tests to check that errors are thrown if
|
|
|
|
// unimplemented AMF values are attempted to be parsed.
|
|
|
|
std::ifstream fileStream;
|
|
|
|
fileStream.open("AMFBitStreamUnimplementedTest.bin", std::ios::binary);
|
|
|
|
|
|
|
|
// Read a test BitStream from a file
|
|
|
|
std::vector<char> baseBitStream;
|
|
|
|
char byte = 0;
|
|
|
|
while (fileStream.get(byte)) {
|
|
|
|
baseBitStream.push_back(byte);
|
|
|
|
}
|
|
|
|
|
|
|
|
fileStream.close();
|
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
for (auto value : unimplementedValues) {
|
2022-07-20 04:51:05 +00:00
|
|
|
RakNet::BitStream testBitStream;
|
|
|
|
for (auto element : baseBitStream) {
|
|
|
|
testBitStream.Write(element);
|
|
|
|
}
|
2023-05-13 22:22:00 +00:00
|
|
|
testBitStream.Write(value);
|
2022-07-20 04:51:05 +00:00
|
|
|
bool caughtException = false;
|
|
|
|
try {
|
2024-02-26 14:17:22 +00:00
|
|
|
ReadFromBitStream(testBitStream);
|
2023-05-13 22:22:00 +00:00
|
|
|
} catch (eAmf unimplementedValueType) {
|
2022-07-20 04:51:05 +00:00
|
|
|
caughtException = true;
|
|
|
|
}
|
2022-11-07 08:12:35 +00:00
|
|
|
|
2022-07-20 04:51:05 +00:00
|
|
|
ASSERT_EQ(caughtException, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
/**
|
|
|
|
* @brief Test reading a packet capture from live from a BitStream
|
|
|
|
*/
|
|
|
|
TEST(dCommonTests, AMFDeserializeLivePacketTest) {
|
2022-07-20 04:51:05 +00:00
|
|
|
std::ifstream testFileStream;
|
|
|
|
testFileStream.open("AMFBitStreamTest.bin", std::ios::binary);
|
|
|
|
|
|
|
|
// Read a test BitStream from a file
|
|
|
|
RakNet::BitStream testBitStream;
|
|
|
|
char byte = 0;
|
|
|
|
while (testFileStream.get(byte)) {
|
|
|
|
testBitStream.Write<char>(byte);
|
|
|
|
}
|
|
|
|
|
|
|
|
testFileStream.close();
|
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> resultFromFn{ ReadFromBitStream(testBitStream) };
|
|
|
|
auto* result = static_cast<AMFArrayValue*>(resultFromFn.get());
|
2022-07-20 04:51:05 +00:00
|
|
|
// Test the outermost array
|
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(result->Get<std::string>("BehaviorID")->GetValue(), "10447");
|
|
|
|
ASSERT_EQ(result->Get<std::string>("objectID")->GetValue(), "288300744895913279");
|
2022-10-30 20:06:05 +00:00
|
|
|
|
|
|
|
// Test the execution state array
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* executionState = result->GetArray("executionState");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
|
|
|
ASSERT_NE(executionState, nullptr);
|
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto& strips = executionState->GetArray("strips")->GetDense();
|
2022-07-20 04:51:05 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(strips.size(), 1);
|
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* stripsPosition0 = dynamic_cast<AMFArrayValue*>(strips[0]);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* actionIndex = stripsPosition0->Get<double>("actionIndex");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(actionIndex->GetValue(), 0.0f);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* stripIdExecution = stripsPosition0->Get<double>("id");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(stripIdExecution->GetValue(), 0.0f);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* stateIdExecution = executionState->Get<double>("stateID");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(stateIdExecution->GetValue(), 0.0f);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto& states = result->GetArray("states")->GetDense();
|
2022-07-20 04:51:05 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(states.size(), 1);
|
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* firstState = dynamic_cast<AMFArrayValue*>(states[0]);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* stateID = firstState->Get<double>("id");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(stateID->GetValue(), 0.0f);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto& stripsInState = firstState->GetArray("strips")->GetDense();
|
2022-07-20 04:51:05 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(stripsInState.size(), 1);
|
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* firstStrip = dynamic_cast<AMFArrayValue*>(stripsInState[0]);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto& actionsInFirstStrip = firstStrip->GetArray("actions")->GetDense();
|
2022-07-20 04:51:05 +00:00
|
|
|
|
|
|
|
ASSERT_EQ(actionsInFirstStrip.size(), 3);
|
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* actionID = firstStrip->Get<double>("id");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(actionID->GetValue(), 0.0f);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* uiArray = firstStrip->GetArray("ui");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* xPos = uiArray->Get<double>("x");
|
|
|
|
auto* yPos = uiArray->Get<double>("y");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(xPos->GetValue(), 103.0f);
|
|
|
|
ASSERT_EQ(yPos->GetValue(), 82.0f);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* stripId = firstStrip->Get<double>("id");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(stripId->GetValue(), 0.0f);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* firstAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[0]);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* firstType = firstAction->Get<std::string>("Type");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(firstType->GetValue(), "OnInteract");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* firstCallback = firstAction->Get<std::string>("__callbackID__");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(firstCallback->GetValue(), "");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* secondAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[1]);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* secondType = secondAction->Get<std::string>("Type");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(secondType->GetValue(), "FlyUp");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* secondCallback = secondAction->Get<std::string>("__callbackID__");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(secondCallback->GetValue(), "");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* secondDistance = secondAction->Get<double>("Distance");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(secondDistance->GetValue(), 25.0f);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* thirdAction = dynamic_cast<AMFArrayValue*>(actionsInFirstStrip[2]);
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* thirdType = thirdAction->Get<std::string>("Type");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(thirdType->GetValue(), "FlyDown");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* thirdCallback = thirdAction->Get<std::string>("__callbackID__");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(thirdCallback->GetValue(), "");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2024-02-27 07:29:51 +00:00
|
|
|
auto* thirdDistance = thirdAction->Get<double>("Distance");
|
2022-07-20 04:51:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(thirdDistance->GetValue(), 25.0f);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
2022-11-07 08:12:35 +00:00
|
|
|
TEST(dCommonTests, AMFBadConversionTest) {
|
2022-10-30 20:06:05 +00:00
|
|
|
std::ifstream testFileStream;
|
|
|
|
testFileStream.open("AMFBitStreamTest.bin", std::ios::binary);
|
|
|
|
|
|
|
|
// Read a test BitStream from a file
|
|
|
|
RakNet::BitStream testBitStream;
|
|
|
|
char byte = 0;
|
|
|
|
while (testFileStream.get(byte)) {
|
|
|
|
testBitStream.Write<char>(byte);
|
|
|
|
}
|
|
|
|
|
|
|
|
testFileStream.close();
|
|
|
|
|
2024-02-26 14:17:22 +00:00
|
|
|
std::unique_ptr<AMFBaseValue> resultFromFn(ReadFromBitStream(testBitStream));
|
2022-10-30 20:06:05 +00:00
|
|
|
auto result = static_cast<AMFArrayValue*>(resultFromFn.get());
|
|
|
|
|
|
|
|
// Actually a string value.
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(result->Get<double>("BehaviorID"), nullptr);
|
2022-10-30 20:06:05 +00:00
|
|
|
|
|
|
|
// Does not exist in the associative portion
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(result->Get<nullptr_t>("DOES_NOT_EXIST"), nullptr);
|
2022-10-30 20:06:05 +00:00
|
|
|
|
2023-05-13 22:22:00 +00:00
|
|
|
result->Push(true);
|
2022-10-30 20:06:05 +00:00
|
|
|
|
|
|
|
// Exists and is correct type
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_NE(result->Get<bool>(0), nullptr);
|
2022-10-30 20:06:05 +00:00
|
|
|
|
|
|
|
// Value exists but is wrong typing
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(result->Get<std::string>(0), nullptr);
|
2022-10-30 20:06:05 +00:00
|
|
|
|
|
|
|
// Value is out of bounds
|
2023-05-13 22:22:00 +00:00
|
|
|
ASSERT_EQ(result->Get<bool>(1), nullptr);
|
2022-07-20 04:51:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-07-28 13:39:57 +00:00
|
|
|
* Below is the AMF that is in the AMFBitStreamTest.bin file that we are reading in
|
2022-07-20 04:51:05 +00:00
|
|
|
* from a bitstream to test.
|
|
|
|
args: amf3!
|
|
|
|
{
|
|
|
|
"objectID": "288300744895913279",
|
|
|
|
"BehaviorID": "10447",
|
2022-07-28 13:39:57 +00:00
|
|
|
"executionState": amf3!
|
2022-07-20 04:51:05 +00:00
|
|
|
{
|
2022-07-28 13:39:57 +00:00
|
|
|
"strips": amf3!
|
2022-07-20 04:51:05 +00:00
|
|
|
[
|
2022-07-28 13:39:57 +00:00
|
|
|
amf3!
|
2022-07-20 04:51:05 +00:00
|
|
|
{
|
|
|
|
"actionIndex": 0.0,
|
|
|
|
"id": 0.0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
"stateID": 0.0,
|
|
|
|
},
|
|
|
|
"states": amf3!
|
|
|
|
[
|
|
|
|
amf3!
|
|
|
|
{
|
|
|
|
"id": 0.0,
|
|
|
|
"strips": amf3!
|
|
|
|
[
|
|
|
|
amf3!
|
|
|
|
{
|
|
|
|
"actions": amf3!
|
|
|
|
[
|
|
|
|
amf3!
|
|
|
|
{
|
|
|
|
"Type": "OnInteract",
|
|
|
|
"__callbackID__": "",
|
|
|
|
},
|
|
|
|
amf3!
|
|
|
|
{
|
|
|
|
"Distance": 25.0,
|
|
|
|
"Type": "FlyUp",
|
|
|
|
"__callbackID__": "",
|
|
|
|
},
|
|
|
|
amf3!
|
|
|
|
{
|
|
|
|
"Distance": 25.0,
|
|
|
|
"Type": "FlyDown",
|
|
|
|
"__callbackID__": "",
|
|
|
|
},
|
|
|
|
],
|
|
|
|
"id": 0.0,
|
|
|
|
"ui": amf3!
|
|
|
|
{
|
|
|
|
"x": 103.0,
|
|
|
|
"y": 82.0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
*/
|