Skip to content

Commit cee985b

Browse files
committed
Do not read sounds from data source
1 parent 203a104 commit cee985b

File tree

2 files changed

+0
-70
lines changed

2 files changed

+0
-70
lines changed

src/scratch/target.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,18 +331,12 @@ int Target::findCostume(const std::string &costumeName) const
331331
/*! Returns the list of sounds. */
332332
const std::vector<std::shared_ptr<Sound>> &Target::sounds() const
333333
{
334-
if (Target *source = dataSource())
335-
return source->sounds();
336-
337334
return impl->sounds;
338335
}
339336

340337
/*! Adds a sound and returns its index. */
341338
int Target::addSound(std::shared_ptr<Sound> sound)
342339
{
343-
if (Target *source = dataSource())
344-
return source->addSound(sound);
345-
346340
auto it = std::find(impl->sounds.begin(), impl->sounds.end(), sound);
347341

348342
if (it != impl->sounds.end())
@@ -360,9 +354,6 @@ int Target::addSound(std::shared_ptr<Sound> sound)
360354
/*! Returns the sound at index. */
361355
std::shared_ptr<Sound> Target::soundAt(int index) const
362356
{
363-
if (Target *source = dataSource())
364-
return source->soundAt(index);
365-
366357
if (index < 0 || index >= impl->sounds.size())
367358
return nullptr;
368359

@@ -372,9 +363,6 @@ std::shared_ptr<Sound> Target::soundAt(int index) const
372363
/*! Returns the index of the sound with the given name. */
373364
int Target::findSound(const std::string &soundName) const
374365
{
375-
if (Target *source = dataSource())
376-
return source->findSound(soundName);
377-
378366
auto it = std::find_if(impl->sounds.begin(), impl->sounds.end(), [soundName](std::shared_ptr<Sound> sound) { return sound->name() == soundName; });
379367

380368
if (it == impl->sounds.end())

test/scratch_classes/target_test.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,6 @@ TEST(TargetTest, Sounds)
422422
auto s3 = std::make_shared<Sound>("sound3", "", "mp3");
423423

424424
TargetMock target;
425-
EXPECT_CALL(target, dataSource()).Times(14).WillRepeatedly(Return(nullptr));
426-
427425
EXPECT_CALL(*player1, setVolume(1));
428426
EXPECT_CALL(*player2, setVolume(1));
429427
EXPECT_CALL(*player3, setVolume(1));
@@ -444,62 +442,6 @@ TEST(TargetTest, Sounds)
444442
ASSERT_EQ(target.findSound("sound2"), 1);
445443
ASSERT_EQ(target.findSound("sound3"), 2);
446444

447-
// Test with custom data source
448-
Target source;
449-
450-
EXPECT_CALL(target, dataSource()).WillOnce(Return(&source));
451-
452-
ASSERT_TRUE(target.sounds().empty());
453-
454-
TargetMock target2;
455-
EXPECT_CALL(target2, dataSource()).Times(15).WillRepeatedly(Return(&source));
456-
457-
EXPECT_CALL(*player1, setVolume(1));
458-
EXPECT_CALL(*player2, setVolume(1));
459-
EXPECT_CALL(*player3, setVolume(1));
460-
ASSERT_EQ(target2.addSound(s1), 0);
461-
ASSERT_EQ(target2.addSound(s2), 1);
462-
ASSERT_EQ(target2.addSound(s3), 2);
463-
ASSERT_EQ(target2.addSound(s2), 1); // add existing Sound
464-
465-
ASSERT_EQ(target2.sounds(), std::vector<std::shared_ptr<Sound>>({ s1, s2, s3 }));
466-
ASSERT_EQ(target2.soundAt(0), s1);
467-
ASSERT_EQ(target2.soundAt(1), s2);
468-
ASSERT_EQ(target2.soundAt(2), s3);
469-
ASSERT_EQ(target2.soundAt(3), nullptr);
470-
ASSERT_EQ(target2.soundAt(-1), nullptr);
471-
472-
ASSERT_EQ(target2.findSound("invalid"), -1);
473-
ASSERT_EQ(target2.findSound("sound1"), 0);
474-
ASSERT_EQ(target2.findSound("sound2"), 1);
475-
ASSERT_EQ(target2.findSound("sound3"), 2);
476-
477-
ASSERT_EQ(target2.sounds(), source.sounds());
478-
479-
auto player4 = std::make_shared<AudioPlayerMock>();
480-
EXPECT_CALL(factory, createAudioPlayer()).WillOnce(Return(player4));
481-
auto s4 = std::make_shared<Sound>("sound4", "", "wav");
482-
483-
EXPECT_CALL(*player4, setVolume(1));
484-
ASSERT_EQ(source.addSound(s4), 3);
485-
486-
EXPECT_CALL(target2, dataSource()).WillOnce(Return(&source));
487-
ASSERT_EQ(target2.sounds(), source.sounds());
488-
489-
ASSERT_EQ(source.sounds(), std::vector<std::shared_ptr<Sound>>({ s1, s2, s3, s4 }));
490-
ASSERT_EQ(source.soundAt(0), s1);
491-
ASSERT_EQ(source.soundAt(1), s2);
492-
ASSERT_EQ(source.soundAt(2), s3);
493-
ASSERT_EQ(source.soundAt(3), s4);
494-
ASSERT_EQ(source.soundAt(4), nullptr);
495-
ASSERT_EQ(source.soundAt(-1), nullptr);
496-
497-
ASSERT_EQ(source.findSound("invalid"), -1);
498-
ASSERT_EQ(source.findSound("sound1"), 0);
499-
ASSERT_EQ(source.findSound("sound2"), 1);
500-
ASSERT_EQ(source.findSound("sound3"), 2);
501-
ASSERT_EQ(source.findSound("sound4"), 3);
502-
503445
SoundPrivate::audioOutput = nullptr;
504446
}
505447

0 commit comments

Comments
 (0)