Fix some implicit int to bool conversions

This commit is contained in:
Dmitry Marakasov 2020-06-17 18:34:03 +03:00
parent e6a42db209
commit c7351716c0
6 changed files with 32 additions and 32 deletions

View File

@ -95,7 +95,7 @@ Font& Font::SetHinting(int hinting) {
} }
bool Font::GetKerning() const { bool Font::GetKerning() const {
return TTF_GetFontKerning(font_); return TTF_GetFontKerning(font_) > 0;
} }
Font& Font::SetKerning(bool allowed) { Font& Font::SetKerning(bool allowed) {
@ -124,7 +124,7 @@ long Font::GetNumFaces() const {
} }
bool Font::IsFixedWidth() const { bool Font::IsFixedWidth() const {
return TTF_FontFaceIsFixedWidth(font_); return TTF_FontFaceIsFixedWidth(font_) > 0;
} }
Optional<std::string> Font::GetFamilyName() const { Optional<std::string> Font::GetFamilyName() const {

View File

@ -213,15 +213,15 @@ void Mixer::HaltMusic() {
} }
bool Mixer::FadeOutMusic(int ms) { bool Mixer::FadeOutMusic(int ms) {
return Mix_FadeOutMusic(ms); return Mix_FadeOutMusic(ms) > 0;
} }
bool Mixer::IsMusicPlaying() const { bool Mixer::IsMusicPlaying() const {
return Mix_PlayingMusic(); return Mix_PlayingMusic() > 0;
} }
bool Mixer::IsMusicPaused() const { bool Mixer::IsMusicPaused() const {
return Mix_PausedMusic(); return Mix_PausedMusic() > 0;
} }
Mix_Fading Mixer::GetMusicFading() const { Mix_Fading Mixer::GetMusicFading() const {

View File

@ -32,18 +32,18 @@ BEGIN_TEST(int, char*[])
auto rwops = RWops::FromFile(TESTDATA_DIR "/test.ogg"); auto rwops = RWops::FromFile(TESTDATA_DIR "/test.ogg");
Chunk chunk_by_rw(rwops); Chunk chunk_by_rw(rwops);
EXPECT_TRUE(chunk_by_rw.Get()); EXPECT_TRUE(chunk_by_rw.Get() != nullptr);
rwops.Seek(0, RW_SEEK_SET); rwops.Seek(0, RW_SEEK_SET);
Music music_by_rw1(rwops); Music music_by_rw1(rwops);
EXPECT_TRUE(music_by_rw1.Get()); EXPECT_TRUE(music_by_rw1.Get() != nullptr);
EXPECT_EQUAL(music_by_rw1.GetType(), MUS_OGG); EXPECT_EQUAL(music_by_rw1.GetType(), MUS_OGG);
rwops.Seek(0, RW_SEEK_SET); rwops.Seek(0, RW_SEEK_SET);
Music music_by_rw2(rwops, MUS_OGG); Music music_by_rw2(rwops, MUS_OGG);
EXPECT_TRUE(music_by_rw2.Get()); EXPECT_TRUE(music_by_rw2.Get() != nullptr);
EXPECT_EQUAL(music_by_rw2.GetType(), MUS_OGG); EXPECT_EQUAL(music_by_rw2.GetType(), MUS_OGG);
// bad format // bad format

View File

@ -45,8 +45,8 @@ public:
bool Test3x3(int x, int y, int mask, int r, int g, int b, int a = -1) { bool Test3x3(int x, int y, int mask, int r, int g, int b, int a = -1) {
for (int dy = -1; dy <= 1; dy++) { for (int dy = -1; dy <= 1; dy++) {
for (int dx = -1; dx <= 1; dx++) { for (int dx = -1; dx <= 1; dx++) {
bool maskbit = mask & (1 << ((1 - dx) + (1 - dy) * 4)); bool maskbit = !!(mask & (1 << ((1 - dx) + (1 - dy) * 4)));
if (Test(x + dx, y + dy, r, g, b, a) != !!maskbit) if (Test(x + dx, y + dy, r, g, b, a) != maskbit)
return false; return false;
} }
} }
@ -59,15 +59,15 @@ BEGIN_TEST(int, char*[])
{ {
// SDL initialization stuff // SDL initialization stuff
EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO)); EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO) > 0);
sdl.QuitSubSystem(SDL_INIT_VIDEO); sdl.QuitSubSystem(SDL_INIT_VIDEO);
EXPECT_TRUE(!sdl.WasInit(SDL_INIT_VIDEO)); EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO) == 0);
sdl.InitSubSystem(SDL_INIT_VIDEO); sdl.InitSubSystem(SDL_INIT_VIDEO);
EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO)); EXPECT_TRUE(sdl.WasInit(SDL_INIT_VIDEO) > 0);
} }
Window window("libSDL2pp test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, 0); Window window("libSDL2pp test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, 0);

View File

@ -120,33 +120,33 @@ BEGIN_TEST(int, char*[])
// Flags // Flags
std::cerr << "Window flags: " << std::hex << "0x" << window.GetFlags() << std::dec << std::endl; std::cerr << "Window flags: " << std::hex << "0x" << window.GetFlags() << std::dec << std::endl;
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_SHOWN); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_SHOWN, SDL_WINDOW_SHOWN);
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_RESIZABLE); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE);
window.Hide(); window.Hide();
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_SHOWN)); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_SHOWN, 0U);
EventSleep(1000); EventSleep(1000);
window.Show(); window.Show();
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_SHOWN); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_SHOWN, SDL_WINDOW_SHOWN);
EventSleep(1000); EventSleep(1000);
window.Maximize(); window.Maximize();
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_MAXIMIZED); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_MAXIMIZED, SDL_WINDOW_MAXIMIZED);
EventSleep(1000); EventSleep(1000);
window.Restore(); window.Restore();
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_MAXIMIZED)); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_MAXIMIZED, 0U);
EventSleep(1000); EventSleep(1000);
window.Minimize(); window.Minimize();
EventSleep(1000); // Minimization may take some time, e.g. on Ubuntu due to animations EventSleep(1000); // Minimization may take some time, e.g. on Ubuntu due to animations
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_MINIMIZED, "May fail on some WMs", NON_FATAL); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_MINIMIZED, SDL_WINDOW_MINIMIZED, "May fail on some WMs", NON_FATAL);
EventSleep(1000); EventSleep(1000);
window.Restore(); window.Restore();
EventSleep(1000); // Restore from minimized state may take some time, e.g. on Ubuntu due to animations EventSleep(1000); // Restore from minimized state may take some time, e.g. on Ubuntu due to animations
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_MINIMIZED)); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_MINIMIZED, 0U);
EventSleep(1000); EventSleep(1000);
// May hang until window is moved (SDL bug?) // May hang until window is moved (SDL bug?)
@ -183,11 +183,11 @@ BEGIN_TEST(int, char*[])
{ {
// Fullscreen // Fullscreen
window.SetFullscreen(SDL_WINDOW_FULLSCREEN_DESKTOP); window.SetFullscreen(SDL_WINDOW_FULLSCREEN_DESKTOP);
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_FULLSCREEN_DESKTOP); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_FULLSCREEN_DESKTOP, SDL_WINDOW_FULLSCREEN_DESKTOP);
EventSleep(1000); EventSleep(1000);
window.SetFullscreen(0); window.SetFullscreen(0);
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_FULLSCREEN_DESKTOP)); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_FULLSCREEN_DESKTOP, 0U);
EventSleep(1000); EventSleep(1000);
} }
@ -219,19 +219,19 @@ BEGIN_TEST(int, char*[])
if (flags & SDL_WINDOW_RESIZABLE) { if (flags & SDL_WINDOW_RESIZABLE) {
window.SetResizable(false); window.SetResizable(false);
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_RESIZABLE)); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, 0U);
EventSleep(1000); EventSleep(1000);
window.SetResizable(true); window.SetResizable(true);
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_RESIZABLE); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE);
EventSleep(1000); EventSleep(1000);
} else { } else {
window.SetResizable(true); window.SetResizable(true);
EXPECT_TRUE(window.GetFlags() & SDL_WINDOW_RESIZABLE); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, SDL_WINDOW_RESIZABLE);
EventSleep(1000); EventSleep(1000);
window.SetResizable(false); window.SetResizable(false);
EXPECT_TRUE(!(window.GetFlags() & SDL_WINDOW_RESIZABLE)); EXPECT_EQUAL(window.GetFlags() & SDL_WINDOW_RESIZABLE, 0U);
EventSleep(1000); EventSleep(1000);
} }
} }

View File

@ -19,7 +19,7 @@ BEGIN_TEST(int, char*[])
auto rwops = RWops::FromFile(TESTDATA_DIR "/Vera.ttf"); auto rwops = RWops::FromFile(TESTDATA_DIR "/Vera.ttf");
Font font_by_rw(rwops, 30); Font font_by_rw(rwops, 30);
EXPECT_TRUE(font_by_rw.Get()); EXPECT_TRUE(font_by_rw.Get() != nullptr);
} }
MOVE_TEST(Font, font, Get, nullptr); MOVE_TEST(Font, font, Get, nullptr);
@ -97,11 +97,11 @@ BEGIN_TEST(int, char*[])
{ {
// Glyphs provided // Glyphs provided
EXPECT_TRUE(font.IsGlyphProvided(u'A')); EXPECT_TRUE(font.IsGlyphProvided(u'A') > 0);
#ifndef _MSC_VER // MSVC has problems with unicode literals #ifndef _MSC_VER // MSVC has problems with unicode literals
EXPECT_TRUE(font.IsGlyphProvided(u'¼')); EXPECT_TRUE(font.IsGlyphProvided(u'¼') > 0);
EXPECT_TRUE(!font.IsGlyphProvided(u'л')); EXPECT_TRUE(font.IsGlyphProvided(u'л') == 0);
EXPECT_TRUE(!font.IsGlyphProvided(u'Ы')); EXPECT_TRUE(font.IsGlyphProvided(u'Ы') == 0);
#endif #endif
} }