|
1 | 1 | // Copyright 2016-2017 Annotator Team |
2 | 2 | #include <AnnotatorLib/Annotation.h> |
3 | 3 | #include <AnnotatorLib/Commands/CompressObject.h> |
| 4 | +#include <AnnotatorLib/Commands/MergeObjects.h> |
4 | 5 | #include <AnnotatorLib/Commands/NewAnnotation.h> |
5 | 6 | #include <AnnotatorLib/Commands/NewAttribute.h> |
6 | 7 | #include <AnnotatorLib/Commands/RemoveAnnotation.h> |
@@ -203,6 +204,40 @@ TEST_F(commands_test, compressObject) { |
203 | 204 | ASSERT_EQ(obj->getAnnotations().size(), 2ul); |
204 | 205 | } |
205 | 206 |
|
| 207 | +TEST_F(commands_test, mergeObjects) { |
| 208 | + std::shared_ptr<Session> session = std::make_shared<Session>(); |
| 209 | + shared_ptr<Object> first = std::make_shared<Object>(); |
| 210 | + |
| 211 | + for (unsigned long i = 0; i < 5; ++i) { |
| 212 | + shared_ptr<Frame> frame_i = std::make_shared<Frame>(i); |
| 213 | + session->addAnnotation(Annotation::make_shared(frame_i, first)); |
| 214 | + session->getAnnotation(frame_i, first)->setPosition(i * 10, 40, 20, 20); |
| 215 | + ASSERT_EQ(session->getAnnotations().size(), i + 1); |
| 216 | + ASSERT_EQ(session->getFrames().size(), i + 1); |
| 217 | + } |
| 218 | + ASSERT_EQ(session->getFrames().size(), 5ul); |
| 219 | + ASSERT_EQ(first->getAnnotations().size(), 5ul); |
| 220 | + |
| 221 | + shared_ptr<Object> second = std::make_shared<Object>(); |
| 222 | + |
| 223 | + for (unsigned long i = 5; i < 10; ++i) { |
| 224 | + shared_ptr<Frame> frame_i = std::make_shared<Frame>(i); |
| 225 | + session->addAnnotation(Annotation::make_shared(frame_i, second)); |
| 226 | + session->getAnnotation(frame_i, second)->setPosition(i * 10, 40, 20, 20); |
| 227 | + ASSERT_EQ(session->getAnnotations().size(), i + 1); |
| 228 | + ASSERT_EQ(session->getFrames().size(), i + 1); |
| 229 | + } |
| 230 | + ASSERT_EQ(session->getFrames().size(), 10ul); |
| 231 | + ASSERT_EQ(second->getAnnotations().size(), 5ul); |
| 232 | + |
| 233 | + Commands::MergeObjects *cmd = |
| 234 | + new Commands::MergeObjects(session, first, second); |
| 235 | + session->execute(shared_ptr<Commands::Command>(cmd)); |
| 236 | + |
| 237 | + ASSERT_EQ(first->getAnnotations().size(), 10ul); |
| 238 | + ASSERT_EQ(second->getAnnotations().size(), 0ul); |
| 239 | +} |
| 240 | + |
206 | 241 | TEST_F(commands_test, newAttribute) { |
207 | 242 | std::shared_ptr<Session> session = std::make_shared<Session>(); |
208 | 243 | ASSERT_EQ(session->getAnnotations().size(), (unsigned long)0); |
|
0 commit comments