Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Addition and Subtraction Operators #1099

Merged
merged 5 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ui/viewmodels/TriggerConditionViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ void TriggerConditionViewModel::SerializeAppend(std::string& sBuffer) const
sBuffer.push_back('%');
break;

case TriggerOperatorType::Add:
sBuffer.push_back('+');
break;

case TriggerOperatorType::Subtract:
sBuffer.push_back('-');
break;

default:
assert(!"Unknown comparison");
break;
Expand Down Expand Up @@ -519,6 +527,8 @@ static constexpr bool IsModifyingOperator(TriggerOperatorType nType)
case TriggerOperatorType::BitwiseAnd:
case TriggerOperatorType::BitwiseXor:
case TriggerOperatorType::Modulus:
case TriggerOperatorType::Add:
case TriggerOperatorType::Subtract:
return true;

default:
Expand Down
4 changes: 3 additions & 1 deletion src/ui/viewmodels/TriggerConditionViewModel.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ enum class TriggerOperatorType : uint8_t
Divide = RC_OPERATOR_DIV,
BitwiseAnd = RC_OPERATOR_AND,
BitwiseXor = RC_OPERATOR_XOR,
Modulus = RC_OPERATOR_MOD
Modulus = RC_OPERATOR_MOD,
Add = RC_OPERATOR_ADD,
Subtract = RC_OPERATOR_SUB
};

class TriggerConditionViewModel : public ViewModelBase
Expand Down
2 changes: 2 additions & 0 deletions src/ui/viewmodels/TriggerViewModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ TriggerViewModel::TriggerViewModel() noexcept
m_vOperatorTypes.Add(ra::etoi(TriggerOperatorType::Multiply), L"*");
m_vOperatorTypes.Add(ra::etoi(TriggerOperatorType::Divide), L"/");
m_vOperatorTypes.Add(ra::etoi(TriggerOperatorType::Modulus), L"%");
m_vOperatorTypes.Add(ra::etoi(TriggerOperatorType::Add), L"+");
m_vOperatorTypes.Add(ra::etoi(TriggerOperatorType::Subtract), L"-");
m_vOperatorTypes.Add(ra::etoi(TriggerOperatorType::BitwiseAnd), L"&");
m_vOperatorTypes.Add(ra::etoi(TriggerOperatorType::BitwiseXor), L"^");
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/viewmodels/TriggerConditionAsserts.hh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ std::wstring ToString<ra::ui::viewmodels::TriggerOperatorType>(
return L"BitwiseAnd";
case ra::ui::viewmodels::TriggerOperatorType::Modulus:
return L"Modulus";
case ra::ui::viewmodels::TriggerOperatorType::Add:
return L"Add";
case ra::ui::viewmodels::TriggerOperatorType::Subtract:
return L"Subtract";
default:
return std::to_wstring(static_cast<int>(nConditionType));
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/viewmodels/TriggerConditionViewModel_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ TEST_CLASS(TriggerConditionViewModel_Tests)
vmCondition.SetOperator(TriggerOperatorType::Modulus);
Assert::AreEqual(TriggerOperatorType::Modulus, vmCondition.GetOperator());
Assert::IsTrue(vmCondition.HasTarget());

vmCondition.SetOperator(TriggerOperatorType::Add);
Assert::AreEqual(TriggerOperatorType::Add, vmCondition.GetOperator());
Assert::IsTrue(vmCondition.HasTarget());

vmCondition.SetOperator(TriggerOperatorType::Subtract);
Assert::AreEqual(TriggerOperatorType::Subtract, vmCondition.GetOperator());
Assert::IsTrue(vmCondition.HasTarget());
}

TEST_METHOD(TestHasTargetSize)
Expand Down Expand Up @@ -491,6 +499,9 @@ TEST_CLASS(TriggerConditionViewModel_Tests)
ParseAndRegenerate("A:0xH1234"); // none
ParseAndRegenerate("A:0xH1234*5"); // multiply
ParseAndRegenerate("A:0xH1234/5"); // divide
ParseAndRegenerate("A:0xH1234%5"); // modulus
ParseAndRegenerate("A:0xH1234+5"); // addition
ParseAndRegenerate("A:0xH1234-5"); // subtraction
ParseAndRegenerate("A:0xH1234&5"); // bitwise and
}

Expand Down
14 changes: 9 additions & 5 deletions tests/ui/viewmodels/TriggerViewModel_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ TEST_CLASS(TriggerViewModel_Tests)
Assert::AreEqual((int)MemSize::MBF32LE, vmTrigger.OperandSizes().GetItemAt(23)->GetId());
Assert::AreEqual(std::wstring(L"MBF32 LE"), vmTrigger.OperandSizes().GetItemAt(23)->GetLabel());

Assert::AreEqual({ 12U }, vmTrigger.OperatorTypes().Count());
Assert::AreEqual({ 14U }, vmTrigger.OperatorTypes().Count());
Assert::AreEqual((int)TriggerOperatorType::Equals, vmTrigger.OperatorTypes().GetItemAt(0)->GetId());
Assert::AreEqual(std::wstring(L"="), vmTrigger.OperatorTypes().GetItemAt(0)->GetLabel());
Assert::AreEqual((int)TriggerOperatorType::LessThan, vmTrigger.OperatorTypes().GetItemAt(1)->GetId());
Expand All @@ -235,10 +235,14 @@ TEST_CLASS(TriggerViewModel_Tests)
Assert::AreEqual(std::wstring(L"/"), vmTrigger.OperatorTypes().GetItemAt(8)->GetLabel());
Assert::AreEqual((int)TriggerOperatorType::Modulus, vmTrigger.OperatorTypes().GetItemAt(9)->GetId());
Assert::AreEqual(std::wstring(L"%"), vmTrigger.OperatorTypes().GetItemAt(9)->GetLabel());
Assert::AreEqual((int)TriggerOperatorType::BitwiseAnd, vmTrigger.OperatorTypes().GetItemAt(10)->GetId());
Assert::AreEqual(std::wstring(L"&"), vmTrigger.OperatorTypes().GetItemAt(10)->GetLabel());
Assert::AreEqual((int)TriggerOperatorType::BitwiseXor, vmTrigger.OperatorTypes().GetItemAt(11)->GetId());
Assert::AreEqual(std::wstring(L"^"), vmTrigger.OperatorTypes().GetItemAt(11)->GetLabel());
Assert::AreEqual((int)TriggerOperatorType::Add, vmTrigger.OperatorTypes().GetItemAt(10)->GetId());
Assert::AreEqual(std::wstring(L"+"), vmTrigger.OperatorTypes().GetItemAt(10)->GetLabel());
Assert::AreEqual((int)TriggerOperatorType::Subtract, vmTrigger.OperatorTypes().GetItemAt(11)->GetId());
Assert::AreEqual(std::wstring(L"-"), vmTrigger.OperatorTypes().GetItemAt(11)->GetLabel());
Assert::AreEqual((int)TriggerOperatorType::BitwiseAnd, vmTrigger.OperatorTypes().GetItemAt(12)->GetId());
Assert::AreEqual(std::wstring(L"&"), vmTrigger.OperatorTypes().GetItemAt(12)->GetLabel());
Assert::AreEqual((int)TriggerOperatorType::BitwiseXor, vmTrigger.OperatorTypes().GetItemAt(13)->GetId());
Assert::AreEqual(std::wstring(L"^"), vmTrigger.OperatorTypes().GetItemAt(13)->GetLabel());
}

TEST_METHOD(TestParseAndRegenerateCoreOnly)
Expand Down
Loading