-
Notifications
You must be signed in to change notification settings - Fork 41
Create unit test for function bitmap_name #125
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -128,3 +128,62 @@ TEST_CASE("bitmap bounding details can be retrieved", "[bitmap]") | |||||
| } | ||||||
| free_bitmap(bmp); | ||||||
| } | ||||||
|
|
||||||
| TEST_CASE("name can be retrieved from bitmap", "[bitmap][bitmap_name]") | ||||||
| { | ||||||
| SECTION("can get bitmap name") | ||||||
| { | ||||||
| bitmap bmp = load_bitmap("rocket", "rocket_sprt.png"); | ||||||
| REQUIRE(bitmap_valid(bmp)); | ||||||
|
|
||||||
| string name = bitmap_name(bmp); | ||||||
| REQUIRE(name == "rocket"); | ||||||
| } | ||||||
|
|
||||||
| SECTION("empty string returned for bitmap name when passing nullptr") | ||||||
| { | ||||||
| string name = bitmap_name(nullptr); | ||||||
| REQUIRE(name == ""); | ||||||
| } | ||||||
|
|
||||||
| SECTION("empty string returned for bitmap when passing freed bitmap") | ||||||
| { | ||||||
| bitmap bmp = load_bitmap("frog", "frog.png"); | ||||||
sam-stajnko marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| REQUIRE(bitmap_valid(bmp)); | ||||||
|
|
||||||
| free_bitmap(bmp); | ||||||
|
|
||||||
| string name = bitmap_name(bmp); | ||||||
| REQUIRE_FALSE(name == "frog"); | ||||||
| REQUIRE(name == ""); | ||||||
| } | ||||||
|
|
||||||
| SECTION("can get unique names from bitmaps when names are reused") | ||||||
| { | ||||||
| bitmap bmp_1 = create_bitmap("blank", 300, 200); | ||||||
| bitmap bmp_2 = create_bitmap("blank", 800, 600); | ||||||
|
|
||||||
| string name_1 = bitmap_name(bmp_1); | ||||||
| string name_2 = bitmap_name(bmp_2); | ||||||
|
|
||||||
| REQUIRE(name_1 == "blank"); | ||||||
| REQUIRE(name_2 == "blank0"); | ||||||
| } | ||||||
|
|
||||||
| SECTION("can get name of bitmap when name is empty string") | ||||||
| { | ||||||
| bitmap bmp = create_bitmap("", 64, 64); | ||||||
| string name = bitmap_name(bmp); | ||||||
|
|
||||||
| REQUIRE(name == ""); | ||||||
| } | ||||||
|
|
||||||
| SECTION("can get name of bitmap when name includes special characters") | ||||||
| { | ||||||
| string silly_name = "AbCdEf 2+3=5 !@#$% \n"; | ||||||
| bitmap bmp = create_bitmap(silly_name, 128, 128); | ||||||
|
|
||||||
| string returned_name = bitmap_name(bmp); | ||||||
| REQUIRE(returned_name == silly_name); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can also use Catch2's string matchers for assertions with std::strings. For example, to use Equals: using Catch::Matchers::Equals;
Suggested change
I'm not sure if there's a reason to prefer using one over the other, just thought it was worth noting. So don't consider this a required change - I'm half reminding myself here for things to note down in the guide! |
||||||
| } | ||||||
| } | ||||||
Uh oh!
There was an error while loading. Please reload this page.