#pragma once
#include "iter.qh"
+#include "test.qh"
/**
* Maximum amount of creatable lists.
}
}
}
+
+
+#define IL_TEST_BUILD() s = il_test_build(il_test, ent1, ent2, ent3, ent4, ent5)
+
+string il_test_build(entity il_test, entity ent1, entity ent2, entity ent3, entity ent4, entity ent5)
+{
+ IL_CLEAR(il_test);
+ IL_PUSH(il_test, ent1);
+ IL_PUSH(il_test, ent2);
+ IL_PUSH(il_test, ent3);
+ IL_PUSH(il_test, ent4);
+ IL_PUSH(il_test, ent5);
+ return "";
+}
+
+TEST(intrusivelist, ModificationsWhileLooping)
+{
+ IntrusiveList il_test = IL_NEW();
+ entity ent1 = new(1), ent2 = new(2), ent3 = new(3), ent4 = new(4), ent5 = new(5);
+ string s;
+
+ IL_TEST_BUILD();
+ IL_EACH(il_test, true,
+ {
+ s = strcat(s, it.classname);
+ if (it == ent2) IL_REMOVE(il_test, ent3);
+ if (it == ent4) IL_PUSH(il_test, ent3);
+ });
+ EXPECT_TRUE(s == "12453");
+
+ IL_TEST_BUILD();
+ IL_EACH(il_test, true,
+ {
+ s = strcat(s, it.classname);
+ if (it == ent2) IL_REMOVE(il_test, ent2);
+ if (it == ent3) IL_REMOVE(il_test, ent3);
+ if (it == ent3) IL_REMOVE(il_test, ent4);
+ if (it == ent5) IL_POP(il_test);
+ });
+ EXPECT_TRUE(s == "1235");
+
+ IL_TEST_BUILD();
+ IL_REMOVE(il_test, ent5);
+ IL_EACH(il_test, true,
+ {
+ s = strcat(s, it.classname);
+ if (it == ent1) IL_SHIFT(il_test);
+ if (it == ent4) IL_POP(il_test);
+ });
+ EXPECT_TRUE(s == "1234");
+
+ IL_DELETE(il_test);
+ delete(ent1); delete(ent2); delete(ent3); delete(ent4); delete(ent5);
+
+ SUCCEED();
+}