|
| 1 | +#include <scratchcpp/thread.h> |
| 2 | +#include <engine/internal/llvm/llvminstructionlist.h> |
| 3 | +#include <engine/internal/llvm/llvminstruction.h> |
| 4 | +#include <gtest/gtest.h> |
| 5 | + |
| 6 | +using namespace libscratchcpp; |
| 7 | + |
| 8 | +TEST(LLVMInstructionListTest, EmptyList_First) |
| 9 | +{ |
| 10 | + LLVMInstructionList list; |
| 11 | + ASSERT_EQ(list.first(), nullptr); |
| 12 | +} |
| 13 | + |
| 14 | +TEST(LLVMInstructionListTest, EmptyList_Last) |
| 15 | +{ |
| 16 | + LLVMInstructionList list; |
| 17 | + ASSERT_EQ(list.last(), nullptr); |
| 18 | +} |
| 19 | + |
| 20 | +TEST(LLVMInstructionListTest, AddSingleInstruction_First) |
| 21 | +{ |
| 22 | + LLVMInstructionList list; |
| 23 | + auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 24 | + list.addInstruction(ins); |
| 25 | + |
| 26 | + ASSERT_EQ(list.first(), ins.get()); |
| 27 | +} |
| 28 | + |
| 29 | +TEST(LLVMInstructionListTest, AddSingleInstruction_Last) |
| 30 | +{ |
| 31 | + LLVMInstructionList list; |
| 32 | + auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 33 | + list.addInstruction(ins); |
| 34 | + |
| 35 | + ASSERT_EQ(list.last(), ins.get()); |
| 36 | +} |
| 37 | + |
| 38 | +TEST(LLVMInstructionListTest, AddSingleInstruction_Previous) |
| 39 | +{ |
| 40 | + LLVMInstructionList list; |
| 41 | + auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 42 | + list.addInstruction(ins); |
| 43 | + |
| 44 | + ASSERT_EQ(ins->previous, nullptr); |
| 45 | +} |
| 46 | + |
| 47 | +TEST(LLVMInstructionListTest, AddSingleInstruction_Next) |
| 48 | +{ |
| 49 | + LLVMInstructionList list; |
| 50 | + auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 51 | + list.addInstruction(ins); |
| 52 | + |
| 53 | + ASSERT_EQ(ins->next, nullptr); |
| 54 | +} |
| 55 | + |
| 56 | +TEST(LLVMInstructionListTest, AddMultipleInstructions_First) |
| 57 | +{ |
| 58 | + LLVMInstructionList list; |
| 59 | + |
| 60 | + auto ins1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 61 | + list.addInstruction(ins1); |
| 62 | + |
| 63 | + auto ins2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 64 | + list.addInstruction(ins2); |
| 65 | + |
| 66 | + auto ins3 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 67 | + list.addInstruction(ins3); |
| 68 | + |
| 69 | + ASSERT_EQ(list.first(), ins1.get()); |
| 70 | +} |
| 71 | + |
| 72 | +TEST(LLVMInstructionListTest, AddMultipleInstructions_Last) |
| 73 | +{ |
| 74 | + LLVMInstructionList list; |
| 75 | + |
| 76 | + auto ins1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 77 | + list.addInstruction(ins1); |
| 78 | + |
| 79 | + auto ins2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 80 | + list.addInstruction(ins2); |
| 81 | + |
| 82 | + auto ins3 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 83 | + list.addInstruction(ins3); |
| 84 | + |
| 85 | + ASSERT_EQ(list.last(), ins3.get()); |
| 86 | +} |
| 87 | + |
| 88 | +TEST(LLVMInstructionListTest, AddMultipleInstructions_PreviousOfFirst) |
| 89 | +{ |
| 90 | + LLVMInstructionList list; |
| 91 | + |
| 92 | + auto ins1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 93 | + list.addInstruction(ins1); |
| 94 | + |
| 95 | + auto ins2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 96 | + list.addInstruction(ins2); |
| 97 | + |
| 98 | + auto ins3 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 99 | + list.addInstruction(ins3); |
| 100 | + |
| 101 | + ASSERT_EQ(ins1->previous, nullptr); |
| 102 | +} |
| 103 | + |
| 104 | +TEST(LLVMInstructionListTest, AddMultipleInstructions_NextOfFirst) |
| 105 | +{ |
| 106 | + LLVMInstructionList list; |
| 107 | + |
| 108 | + auto ins1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 109 | + list.addInstruction(ins1); |
| 110 | + |
| 111 | + auto ins2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 112 | + list.addInstruction(ins2); |
| 113 | + |
| 114 | + auto ins3 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 115 | + list.addInstruction(ins3); |
| 116 | + |
| 117 | + ASSERT_EQ(ins1->next, ins2.get()); |
| 118 | +} |
| 119 | + |
| 120 | +TEST(LLVMInstructionListTest, AddMultipleInstructions_PreviousOfMiddle) |
| 121 | +{ |
| 122 | + LLVMInstructionList list; |
| 123 | + |
| 124 | + auto ins1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 125 | + list.addInstruction(ins1); |
| 126 | + |
| 127 | + auto ins2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 128 | + list.addInstruction(ins2); |
| 129 | + |
| 130 | + auto ins3 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 131 | + list.addInstruction(ins3); |
| 132 | + |
| 133 | + ASSERT_EQ(ins2->previous, ins1.get()); |
| 134 | +} |
| 135 | + |
| 136 | +TEST(LLVMInstructionListTest, AddMultipleInstructions_NextOfMiddle) |
| 137 | +{ |
| 138 | + LLVMInstructionList list; |
| 139 | + |
| 140 | + auto ins1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 141 | + list.addInstruction(ins1); |
| 142 | + |
| 143 | + auto ins2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 144 | + list.addInstruction(ins2); |
| 145 | + |
| 146 | + auto ins3 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 147 | + list.addInstruction(ins3); |
| 148 | + |
| 149 | + ASSERT_EQ(ins2->next, ins3.get()); |
| 150 | +} |
| 151 | + |
| 152 | +TEST(LLVMInstructionListTest, AddMultipleInstructions_PreviousOfLast) |
| 153 | +{ |
| 154 | + LLVMInstructionList list; |
| 155 | + |
| 156 | + auto ins1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 157 | + list.addInstruction(ins1); |
| 158 | + |
| 159 | + auto ins2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 160 | + list.addInstruction(ins2); |
| 161 | + |
| 162 | + auto ins3 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 163 | + list.addInstruction(ins3); |
| 164 | + |
| 165 | + ASSERT_EQ(ins3->previous, ins2.get()); |
| 166 | +} |
| 167 | + |
| 168 | +TEST(LLVMInstructionListTest, AddMultipleInstructions_NextOfLast) |
| 169 | +{ |
| 170 | + LLVMInstructionList list; |
| 171 | + |
| 172 | + auto ins1 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 173 | + list.addInstruction(ins1); |
| 174 | + |
| 175 | + auto ins2 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 176 | + list.addInstruction(ins2); |
| 177 | + |
| 178 | + auto ins3 = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::FunctionCall, nullptr, false); |
| 179 | + list.addInstruction(ins3); |
| 180 | + |
| 181 | + ASSERT_EQ(ins3->next, nullptr); |
| 182 | +} |
0 commit comments