mirror of
https://github.com/open-goal/jak-project
synced 2026-05-23 23:05:43 -04:00
27f0a7ca44
* refactor tests and analysis passes * identity test working * combine test categories with only a few cases * more fixes
80 lines
2.2 KiB
C++
80 lines
2.2 KiB
C++
#include "gtest/gtest.h"
|
|
#include "FormRegressionTest.h"
|
|
|
|
using namespace decompiler;
|
|
|
|
TEST_F(FormRegressionTest, ExprIdentity) {
|
|
std::string func =
|
|
" sll r0, r0, 0\n"
|
|
" or v0, a0, r0\n"
|
|
" jr ra\n"
|
|
" daddu sp, sp, r0";
|
|
std::string type = "(function object object)";
|
|
std::string expected = "a0-0";
|
|
test_with_expr(func, type, expected);
|
|
}
|
|
|
|
TEST_F(FormRegressionTest, ExprFloatingPoint) {
|
|
std::string func =
|
|
" sll r0, r0, 0\n"
|
|
"L345:\n"
|
|
" daddiu sp, sp, -16\n"
|
|
" sd fp, 8(sp)\n"
|
|
" or fp, t9, r0\n"
|
|
" lwc1 f0, L345(fp)\n"
|
|
" mtc1 f1, a0\n"
|
|
" div.s f0, f0, f1\n"
|
|
" mfc1 v0, f0\n"
|
|
" ld fp, 8(sp)\n"
|
|
" jr ra\n"
|
|
" daddiu sp, sp, 16";
|
|
std::string type = "(function float float)";
|
|
std::string expected = "(/ (l.f L345) a0-0)";
|
|
test_with_expr(func, type, expected);
|
|
}
|
|
|
|
TEST_F(FormRegressionTest, AdditionSigned) {
|
|
std::string func =
|
|
" sll r0, r0, 0\n"
|
|
" daddu v0, a0, a1\n"
|
|
" jr ra\n"
|
|
" daddu sp, sp, r0";
|
|
std::string type = "(function int int int)";
|
|
std::string expected = "(+ a0-0 a1-0)";
|
|
test_with_expr(func, type, expected);
|
|
}
|
|
|
|
TEST_F(FormRegressionTest, AdditionUnSigned) {
|
|
std::string func =
|
|
" sll r0, r0, 0\n"
|
|
" daddu v0, a0, a1\n"
|
|
" jr ra\n"
|
|
" daddu sp, sp, r0";
|
|
std::string type = "(function uint uint uint)";
|
|
std::string expected = "(+ a0-0 a1-0)";
|
|
test_with_expr(func, type, expected);
|
|
}
|
|
|
|
TEST_F(FormRegressionTest, AdditionMixed1) {
|
|
std::string func =
|
|
" sll r0, r0, 0\n"
|
|
" daddu v0, a0, a1\n"
|
|
" jr ra\n"
|
|
" daddu sp, sp, r0";
|
|
std::string type = "(function int uint int)";
|
|
std::string expected = "(+ a0-0 (the-as int a1-0))";
|
|
test_with_expr(func, type, expected);
|
|
}
|
|
|
|
TEST_F(FormRegressionTest, AdditionMixed2) {
|
|
std::string func =
|
|
" sll r0, r0, 0\n"
|
|
" daddu v0, a0, a1\n"
|
|
" jr ra\n"
|
|
" daddu sp, sp, r0";
|
|
std::string type = "(function uint int uint)";
|
|
std::string expected = "(+ a0-0 (the-as uint a1-0))";
|
|
test_with_expr(func, type, expected);
|
|
}
|
|
|
|
// TODO - test the additions, but with the wrong return types.
|