Skip to content

Add unit tests for AudioStreamInteractive #105457

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

Closed
wants to merge 3 commits into from
Closed
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
3 changes: 3 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ else:
# Disable assert() for production targets (only used in thirdparty code).
env.Append(CPPDEFINES=["NDEBUG"])

# adding the line below to remove the error in the control.h file (claimed it could not find core/math)
env.Append(CPPPATH=['#core'])
Copy link
Member

@AThousandShips AThousandShips Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be solved differently, this sounds like an issue either in your compilation setup or something related to your tests, this is not the way to fix it

I suspect that you tried to build from inside test/ which is not correct

But regardless of this the fix should be a separate PR if it is needed, this PR shouldn't contain a buildystem fix

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, on the writing unit test site it said that the tests would fall under tests/ so I got confused, but I can fix that issue. Thank you for pointing me to a helpful file, and I see the formatting is a little different than those in the tests/ folder. Is the one for jsonrpc the expected unit tests?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean for formatting? And what file? Did you mean to reply to my other comment?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I meant to reply to your other comment apologies.


# This is not part of fast_unsafe because the only downside it has compared to
# the default is that SCons won't mark files that were changed in the last second
# as different. This is unlikely to be a problem in any real situation as just booting
Expand Down
90 changes: 90 additions & 0 deletions modules/interactive_music/tests/test_audio_stream_interactive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/**************************************************************************/
/* test_audio_stream_interactive.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#pragma once

#include "tests/test_macros.h"
#include "tests/test_utils.h"
#include "servers/audio/audio_stream.h"

#include "../audio_stream_interactive.h"


namespace TestAudio_stream_interactive {

TEST_CASE("[AudioStreamInteractive] test_is_initialized_and_default") {
Ref<AudioStreamInteractive> stream;
stream.instantiate();
CHECK(stream.is_valid());

//checking default values
CHECK(stream->get_stream_name() == "Transitioner");
}

TEST_CASE("[AudioStreamInteractive] test_clip_count") {
Ref<AudioStreamInteractive> stream;
stream.instantiate();
CHECK(stream.is_valid());
CHECK(stream->get_initial_clip() == 0);

CHECK(stream->get_clip_count() == 0);
}

TEST_CASE("[AudioStreamInteractive] test_clip_name") {
Ref<AudioStreamInteractive> stream;
stream.instantiate();
CHECK(stream.is_valid());

//checking setting and getting clip name
StringName name = "file1";
stream->set_clip_name(0, name);
CHECK(stream->get_clip_name(0) == name);
}

TEST_CASE("[AudioStreamInteractive] test_instantiate_playback") {
Ref<AudioStreamInteractive> stream;
stream.instantiate();
CHECK(stream.is_valid());

Ref<AudioStreamPlaybackInteractive> playback = stream->instantiate_playback();
CHECK(playback.is_valid());
}

TEST_CASE("[AudioStreamPlaybackInteractive] test_playback"){
Ref<AudioStreamPlaybackInteractive> playback;
playback.instantiate();
CHECK(playback.is_valid());

CHECK(playback->is_playing() == false);
CHECK(playback->get_loop_count() == 0);
CHECK(playback->get_playback_position() == 0.0);
}

} // namespace TestAudio_stream_interactive
66 changes: 66 additions & 0 deletions modules/interactive_music/tests/test_audio_stream_playlist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**************************************************************************/
/* test_audio_stream_playlist.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#pragma once

#include "tests/test_macros.h"
#include "tests/test_utils.h"
#include "servers/audio/audio_stream.h"

#include "../audio_stream_playlist.h"

namespace TestAudio_stream_playlist {

TEST_CASE("[AudioStreamPlaylist] test_initialized_and_default") {
Ref<AudioStreamPlaylist> playlist;
playlist.instantiate();
CHECK(playlist.is_valid());

// checking default settings
CHECK(playlist->get_stream_name() == "Playlist");
CHECK(playlist->get_shuffle() == false);
CHECK(playlist->get_fade_time() == float(0.3));
CHECK(playlist->has_loop() == true);
CHECK(playlist->get_stream_count() == 0);
CHECK(playlist->get_length() == 0.0);
CHECK(playlist->is_meta_stream() == true);
CHECK(playlist->get_bpm() == 0.0);
}

TEST_CASE("[AudioStreamPlaylist] test_instantiate_playback") {
Ref<AudioStreamPlaylist> playlist;
playlist.instantiate();
CHECK(playlist.is_valid());

Ref<AudioStreamPlayback> playback = playlist->instantiate_playback();
CHECK(playback.is_valid());
}

} // namespace TestAudio_stream_playlist
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**************************************************************************/
/* test_audio_stream_synchronized.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#pragma once

#include "tests/test_macros.h"
#include "tests/test_utils.h"
#include "servers/audio/audio_stream.h"

#include "../audio_stream_synchronized.h"

namespace TestAudio_stream_synchronized {

TEST_CASE("[AudioStreamSynchronized] test_initialized_and_default") {
Ref<AudioStreamSynchronized> synchro;
synchro.instantiate();
CHECK(synchro.is_valid());

//testing default values
CHECK(synchro->get_stream_count() == 0);
CHECK(synchro->get_beat_count() == 0);
CHECK(synchro->get_bpm() == 0.0);
CHECK(synchro->get_bar_beats() == 0);
CHECK(synchro->get_stream_name() == "Synchronized");
}

} // namespace TestAudio_stream_synchronized
2 changes: 1 addition & 1 deletion scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

#pragma once

#include "core/math/transform_2d.h"
#include "core/math/transform_2d.h" //this include is giving errors
#include "core/object/gdvirtual.gen.inc"
#include "scene/main/canvas_item.h"
#include "scene/main/timer.h"
Expand Down
88 changes: 88 additions & 0 deletions tests/modules/interactive_music/test_audio_stream_interactive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**************************************************************************/
/* test_audio_stream_interactive.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#pragma once

#include "tests/test_macros.h"
#include "modules/interactive_music/audio_stream_interactive.h"
#include "servers/audio/audio_stream.h"


namespace TestAudio_stream_interactive {

TEST_CASE("[AudioStreamInteractive] test_is_initialized_and_default") {
Ref<AudioStreamInteractive> stream;
stream.instantiate();
CHECK(stream.is_valid());

//checking default values
CHECK(stream->get_stream_name() == "Transitioner");
}

TEST_CASE("[AudioStreamInteractive] test_clip_count") {
Ref<AudioStreamInteractive> stream;
stream.instantiate();
CHECK(stream.is_valid());
CHECK(stream->get_initial_clip() == 0);

CHECK(stream->get_clip_count() == 0);
}

TEST_CASE("[AudioStreamInteractive] test_clip_name") {
Ref<AudioStreamInteractive> stream;
stream.instantiate();
CHECK(stream.is_valid());

//checking setting and getting clip name
StringName name = "file1";
stream->set_clip_name(0, name);
CHECK(stream->get_clip_name(0) == name);
}

TEST_CASE("[AudioStreamInteractive] test_instantiate_playback") {
Ref<AudioStreamInteractive> stream;
stream.instantiate();
CHECK(stream.is_valid());

Ref<AudioStreamPlaybackInteractive> playback = stream->instantiate_playback();
CHECK(playback.is_valid());
}

TEST_CASE("[AudioStreamPlaybackInteractive] test_playback"){
Ref<AudioStreamPlaybackInteractive> playback;
playback.instantiate();
CHECK(playback.is_valid());

CHECK(playback->is_playing() == false);
CHECK(playback->get_loop_count() == 0);
CHECK(playback->get_playback_position() == 0.0);
}

} // namespace TestAudio_stream_interactive
64 changes: 64 additions & 0 deletions tests/modules/interactive_music/test_audio_stream_playlist.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**************************************************************************/
/* test_audio_stream_playlist.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#pragma once

#include "tests/test_macros.h"
#include "modules/interactive_music/audio_stream_playlist.h"
#include "servers/audio/audio_stream.h"

namespace TestAudio_stream_playlist {

TEST_CASE("[AudioStreamPlaylist] test_initialized_and_default") {
Ref<AudioStreamPlaylist> playlist;
playlist.instantiate();
CHECK(playlist.is_valid());

// checking default settings
CHECK(playlist->get_stream_name() == "Playlist");
CHECK(playlist->get_shuffle() == false);
CHECK(playlist->get_fade_time() == float(0.3));
CHECK(playlist->has_loop() == true);
CHECK(playlist->get_stream_count() == 0);
CHECK(playlist->get_length() == 0.0);
CHECK(playlist->is_meta_stream() == true);
CHECK(playlist->get_bpm() == 0.0);
}

TEST_CASE("[AudioStreamPlaylist] test_instantiate_playback") {
Ref<AudioStreamPlaylist> playlist;
playlist.instantiate();
CHECK(playlist.is_valid());

Ref<AudioStreamPlayback> playback = playlist->instantiate_playback();
CHECK(playback.is_valid());
}

} // namespace TestAudio_stream_playlist
Loading
Loading