delta tests and service

This commit is contained in:
scawful
2022-09-26 20:27:16 -05:00
parent 03bf3d3255
commit d469c9273b
6 changed files with 132 additions and 86 deletions

View File

@@ -33,6 +33,7 @@ absl::Status Client::InitRepo(std::string author_name,
Repository new_repo;
new_repo.set_author_name(author_name);
new_repo.set_project_name(project_name);
new_repo.mutable_tree()->Add();
InitRequest request;
request.set_allocated_repo(&new_repo);

View File

@@ -18,13 +18,30 @@ service YazeDelta {
rpc UndoMerge(UndoMergeRequest) returns (UndoMergeResponse) {}
}
enum ChangeType {
OVERWORLD_MAP = 0;
DUNGEON_MAP = 1;
MONOLOGUE = 2;
PALETTE = 3;
OBJECT = 4;
ASSEMBLY = 5;
MISC = 6;
}
message Delta {
int64 offset = 1;
int64 length = 2;
bytes data = 3;
ChangeType type = 4;
}
message Commit {
int64 commit_id = 1;
int64 parent_commit_id = 2;
string author_name = 3;
string message_header = 4;
optional string message_body = 5;
bytes data = 6;
repeated Delta delta = 6;
int64 signature = 7;
}
@@ -63,7 +80,12 @@ message PushRequest {
}
message PushResponse {}
message PullRequest {}
message PullRequest {
string repository_name = 1;
string branch_name = 2;
repeated Commit commits = 3;
}
message PullResponse {}
message SyncRequest {}

View File

@@ -6,6 +6,8 @@
#include <grpcpp/grpcpp.h>
#include <grpcpp/health_check_service_interface.h>
#include <fstream>
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "src/app/delta/delta.grpc.pb.h"
@@ -46,6 +48,14 @@ Status DeltaService::Init(grpc::ServerContext* context,
const InitRequest* request, InitResponse* reply) {
std::filesystem::create_directories("./.yaze");
repos_.push_back(request->repo());
// std::ofstream commit_stream("./.yaze/commits");
// for (const auto& repo : repos_) {
// for (const auto& branch : repo.tree()) {
// for (const auto& commit : branch.commits()) {
// commit_stream << commit.DebugString();
// }
// }
// }
return Status::OK;
}

View File

@@ -14,7 +14,7 @@ void Inventory::Create() {
data_.push_back(0xFF);
}
PRINT_IF_ERROR(BuildTileset())
for (int i = 0; i < 0x400; i += 0x08) {
for (int i = 0; i < 0x500; i += 0x08) {
tiles_.push_back(gfx::GetTilesInfo(rom_.toint16(i + kBowItemPos)));
tiles_.push_back(gfx::GetTilesInfo(rom_.toint16(i + kBowItemPos + 0x02)));
tiles_.push_back(gfx::GetTilesInfo(rom_.toint16(i + kBowItemPos + 0x04)));

View File

@@ -1,8 +1,7 @@
#include <asar/interface-lib.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <google/protobuf/repeated_field.h>
#include <gtest/gtest.h>
#include <array>
#include <cstdint>
@@ -14,12 +13,12 @@
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "app/core/constants.h"
#include "app/delta/client.h"
#include "app/delta/service.h"
#include "app/core/constants.h"
#include "app/rom.h"
#include "src/app/delta/delta.grpc.pb.h"
#include "src/app/delta/delta.pb.h"
#include "app/rom.h"
namespace yaze_test {
namespace delta_test {
@@ -29,7 +28,7 @@ TEST(DeltaTest, InitRepoAndPushOk) {
yaze::app::ROM rom;
Bytes test_bytes;
test_bytes.push_back(0x40);
rom.LoadFromBytes(test_bytes);
EXPECT_TRUE(rom.LoadFromBytes(test_bytes).ok());
grpc::ServerContext* context;
InitRequest init_request;
auto repo = init_request.mutable_repo();
@@ -41,7 +40,6 @@ TEST(DeltaTest, InitRepoAndPushOk) {
for (int i = 0; i < 5; ++i) {
auto new_commit = new Commit();
new_commit->set_commit_id(i);
new_commit->set_data(rom.char_data());
new_mutable_commits->Add();
new_mutable_commits->at(i) = *new_commit;
}
@@ -72,7 +70,5 @@ TEST(DeltaTest, InitRepoAndPushOk) {
std::cerr << result_branch.at(0).DebugString() << std::endl;
}
} // namespace asm_test
} // namespace delta_test
} // namespace yaze_test

View File

@@ -21,7 +21,6 @@ using ::testing::TypedEq;
namespace {
Bytes ExpectCompressOk(ROM& rom, uchar* in, int in_size) {
Bytes result;
auto load_status = rom.LoadFromPointer(in, in_size);
EXPECT_TRUE(load_status.ok());
auto compression_status = rom.Compress(0, in_size);
@@ -30,6 +29,15 @@ Bytes ExpectCompressOk(ROM& rom, uchar* in, int in_size) {
return compressed_bytes;
}
Bytes ExpectDecompressBytesOk(ROM& rom, Bytes& in) {
auto load_status = rom.LoadFromBytes(in);
EXPECT_TRUE(load_status.ok());
auto decompression_status = rom.Decompress(0, in.size());
EXPECT_TRUE(decompression_status.ok());
auto decompressed_bytes = std::move(*decompression_status);
return decompressed_bytes;
}
Bytes ExpectDecompressOk(ROM& rom, uchar* in, int in_size) {
auto load_status = rom.LoadFromPointer(in, in_size);
EXPECT_TRUE(load_status.ok());
@@ -74,10 +82,9 @@ TEST(ROMTest, NewDecompressionPieceOk) {
TEST(ROMTest, DecompressionValidCommand) {
ROM rom;
std::array<uchar, 4> simple_copy_input = {BUILD_HEADER(0x00, 0x02), 0x2A,
0x45, 0xFF};
Bytes simple_copy_input = {BUILD_HEADER(0x00, 0x02), 0x2A, 0x45, 0xFF};
uchar simple_copy_output[2] = {0x2A, 0x45};
auto decomp_result = ExpectDecompressOk(rom, simple_copy_input.data(), 4);
auto decomp_result = ExpectDecompressBytesOk(rom, simple_copy_input);
EXPECT_THAT(simple_copy_output, ElementsAreArray(decomp_result.data(), 2));
}
@@ -99,34 +106,6 @@ TEST(ROMTest, DecompressionMixingCommand) {
EXPECT_THAT(random1_o, ElementsAreArray(decomp_result.data(), 9));
}
/* Extended Header Command is currently unimplemented
TEST(ROMTest, ExtendedHeaderDecompress) {
ROM rom;
uchar extendedcmd_i[4] = {0b11100100, 0x8F, 0x2A, 0xFF};
uchar extendedcmd_o[50];
for (int i = 0; i < 50; ++i) {
extendedcmd_o[i] = 0x2A;
}
auto decomp_result = ExpectDecompressOk(rom, extendedcmd_i, 4);
ASSERT_THAT(extendedcmd_o, ElementsAreArray(decomp_result.data(), 50));
}
TEST(ROMTest, ExtendedHeaderDecompress2) {
ROM rom;
uchar extendedcmd_i[4] = {0b11100101, 0x8F, 0x2A, 0xFF};
uchar extendedcmd_o[50];
for (int i = 0; i < 50; i++) {
extendedcmd_o[i] = 0x2A;
}
auto data = ExpectDecompressOk(rom, extendedcmd_i, 4);
for (int i = 0; i < 50; i++) {
ASSERT_EQ(extendedcmd_o[i], data[i]);
}
}
*/
TEST(ROMTest, CompressionSingleSet) {
ROM rom;
uchar single_set[5] = {0x2A, 0x2A, 0x2A, 0x2A, 0x2A};
@@ -162,7 +141,6 @@ TEST(ROMTest, CompressionSingleCopy) {
EXPECT_THAT(single_copy_expected, ElementsAreArray(comp_result.data(), 6));
}
/* Hiding tests until I figure out a better PR to address the bug
TEST(ROMTest, CompressionSingleCopyRepeat) {
ROM rom;
uchar single_copy_repeat[8] = {0x03, 0x0A, 0x07, 0x14, 0x03, 10, 0x07, 0x14};
@@ -171,9 +149,10 @@ TEST(ROMTest, CompressionSingleCopyRepeat) {
BUILD_HEADER(0x04, 0x04), 0x00, 0x00, 0xFF};
auto comp_result = ExpectCompressOk(rom, single_copy_repeat, 8);
EXPECT_THAT(single_copy_repeat_expected,
ElementsAreArray(comp_result.data(), 8));
ElementsAreArray(comp_result.data(), 9));
}
/* Hiding tests until I figure out a better PR to address the bug
TEST(ROMTest, CompressionSingleOverflowIncrement) {
ROM rom;
uchar overflow_inc[4] = {0xFE, 0xFF, 0x00, 0x01};
@@ -201,26 +180,14 @@ TEST(ROMTest, CompressionMixedRepeatIncrement) {
EXPECT_THAT(repeat_and_inc_copy_expected,
ElementsAreArray(comp_result.data(), 7));
}
*/
TEST(ROMTest, SimpleMixCompression) {
TEST(ROMTest, CompressionMixedIncrementIntraCopyOffset) {
ROM rom;
uchar to_compress_string[] = {0x05, 0x05, 0x05, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x05, 0x02, 0x05, 0x02,
0x05, 0x02, 0x0A, 0x0B, 0x05, 0x02, 0x05,
0x02, 0x05, 0x02, 0x08, 0x0A, 0x00, 0x05};
uchar repeat_and_inc_copy_expected[] = {BUILD_HEADER(0x01, 0x04),
0x05,
BUILD_HEADER(0x03, 0x06),
0x06,
BUILD_HEADER(0x00, 0x01),
0x05,
0xFF};
// Mixing, repeat, inc, trailing copy
auto data = ExpectCompressOk(rom, to_compress_string, 7);
for (int i = 0; i < 7; ++i) {
EXPECT_EQ(repeat_and_inc_copy_expected[i], data[i]);
}
uchar inc_word_intra_copy_expected[] = {BUILD_HEADER(0x03, 0x07),
0x05,
BUILD_HEADER(0x02, 0x06),
@@ -230,10 +197,21 @@ TEST(ROMTest, SimpleMixCompression) {
0x05,
0x00,
0xFF};
// CuAssertDataEquals_Msg(
// tc, "Mixing, inc, alternate, intra copy", inc_word_intra_copy_expected,
// 9, alttp_compress_gfx(to_compress_string, 3, 21, &compress_size));
// "Mixing, inc, alternate, intra copy"
// compress start: 3, length: 21
// compressed length: 9
auto comp_result = ExpectCompressOk(rom, to_compress_string + 3, 21);
EXPECT_THAT(inc_word_intra_copy_expected,
ElementsAreArray(comp_result.data(), 9));
}
TEST(ROMTest, CompressionMixedIncrementIntraCopySource) {
ROM rom;
uchar to_compress_string[] = {0x05, 0x05, 0x05, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x05, 0x02, 0x05, 0x02,
0x05, 0x02, 0x0A, 0x0B, 0x05, 0x02, 0x05,
0x02, 0x05, 0x02, 0x08, 0x0A, 0x00, 0x05};
uchar all_expected[] = {BUILD_HEADER(0x01, 0x04),
0x05,
BUILD_HEADER(0x03, 0x06),
@@ -250,15 +228,16 @@ TEST(ROMTest, SimpleMixCompression) {
0x00,
0x05,
0xFF};
// CuAssertDataEquals_Msg(
// tc, "Mixing, inc, alternate, intra copy", all_expected, 16,
// alttp_compress_gfx(to_compress_string, 0, 28, &compress_size));
// "Mixing, inc, alternate, intra copy"
// 0, 28
// 16
auto comp_result = ExpectCompressOk(rom, to_compress_string, 28);
EXPECT_THAT(all_expected, ElementsAreArray(comp_result.data(), 16));
}
*/
TEST(ROMTest, LengthBorderCompression) {
char buffer[3000];
unsigned int compress_size;
ROM rom;
uchar buffer[3000];
for (unsigned int i = 0; i < 3000; i++) buffer[i] = 0x05;
uchar extended_lenght_expected_42[] = {0b11100100, 0x29, 0x05, 0xFF};
@@ -268,31 +247,69 @@ TEST(ROMTest, LengthBorderCompression) {
uchar extended_lenght_expected_2050[] = {
0b11100111, 0xFF, 0x05, 0b11100111, 0xFF, 0x05, BUILD_HEADER(0x01, 0x02),
0x05, 0xFF};
// CuAssertDataEquals_Msg(tc, "Extended lenght, 42 repeat of 5",
// extended_lenght_expected_42, 4,
// alttp_compress_gfx(buffer, 0, 42, &compress_size));
// CuAssertDataEquals_Msg(tc, "Extended lenght, 400 repeat of 5",
// extended_lenght_expected_400, 4,
// alttp_compress_gfx(buffer, 0, 400, &compress_size));
// CuAssertDataEquals_Msg(tc, "Extended lenght, 1050 repeat of 5",
// extended_lenght_expected_1050, 6,
// alttp_compress_gfx(buffer, 0, 1050,
// &compress_size));
// CuAssertDataEquals_Msg(tc, "Extended lenght, 2050 repeat of 5",
// extended_lenght_expected_2050, 9,
// alttp_compress_gfx(buffer, 0, 2050,
// &compress_size));
// "Extended lenght, 42 repeat of 5"
auto comp_result = ExpectCompressOk(rom, buffer, 42);
EXPECT_THAT(extended_lenght_expected_42,
ElementsAreArray(comp_result.data(), 4));
// "Extended lenght, 400 repeat of 5"
comp_result = ExpectCompressOk(rom, buffer, 400);
EXPECT_THAT(extended_lenght_expected_400,
ElementsAreArray(comp_result.data(), 4));
// "Extended lenght, 1050 repeat of 5"
comp_result = ExpectCompressOk(rom, buffer, 1050);
EXPECT_THAT(extended_lenght_expected_1050,
ElementsAreArray(comp_result.data(), 6));
// "Extended lenght, 2050 repeat of 5"
comp_result = ExpectCompressOk(rom, buffer, 2050);
EXPECT_THAT(extended_lenght_expected_2050,
ElementsAreArray(comp_result.data(), 9));
}
TEST(ROMTest, CompressionExtendedWordCopy) {
ROM rom;
uchar buffer[3000];
for (unsigned int i = 0; i < 3000; i += 2) {
buffer[i] = 0x05;
buffer[i + 1] = 0x06;
}
uchar hightlenght_word_1050[] = {
0b11101011, 0xFF, 0x05, 0x06, BUILD_HEADER(0x02, 0x1A), 0x05, 0x06, 0xFF};
// CuAssertDataEquals_Msg(tc, "Extended word copy", hightlenght_word_1050, 8,
// alttp_compress_gfx(buffer, 0, 1050,
// &compress_size));
// "Extended word copy"
auto comp_result = ExpectCompressOk(rom, buffer, 1050);
EXPECT_THAT(hightlenght_word_1050, ElementsAreArray(comp_result.data(), 8));
}
/* Extended Header Command is currently unimplemented
TEST(ROMTest, ExtendedHeaderDecompress) {
ROM rom;
Bytes extendedcmd_i = {0b11100100, 0x8F, 0x2A, 0xFF};
uchar extendedcmd_o[50];
for (int i = 0; i < 50; ++i) {
extendedcmd_o[i] = 0x2A;
}
auto decomp_result = ExpectDecompressBytesOk(rom, extendedcmd_i);
ASSERT_THAT(extendedcmd_o, ElementsAreArray(decomp_result.data(), 50));
}
TEST(ROMTest, ExtendedHeaderDecompress2) {
ROM rom;
Bytes extendedcmd_i = {0b11100101, 0x8F, 0x2A, 0xFF};
uchar extendedcmd_o[50];
for (int i = 0; i < 50; i++) {
extendedcmd_o[i] = 0x2A;
}
auto data = ExpectDecompressBytesOk(rom, extendedcmd_i);
for (int i = 0; i < 50; i++) {
ASSERT_EQ(extendedcmd_o[i], data[i]);
}
}
*/
} // namespace rom_test
} // namespace yaze_test