2
* Copyright © 2015 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Alexandros Frantzis <alexandros.frantzis@canonical.com>
19
#include "mir/graphics/egl_error.h"
20
#include "mir_test_doubles/mock_egl.h"
22
#include <gtest/gtest.h>
23
#include <gmock/gmock.h>
25
namespace mg = mir::graphics;
26
namespace mtd = mir::test::doubles;
31
std::string to_hex_string(int n)
34
ss << std::showbase << std::hex << n;
38
struct EGLErrorTest : ::testing::Test
40
testing::NiceMock<mtd::MockEGL> mock_egl;
42
std::string const user_message{"Something failed"};
43
std::string const egl_error_code_str{"EGL_BAD_MATCH"};
44
int const egl_error_code{EGL_BAD_MATCH};
49
TEST_F(EGLErrorTest, produces_correct_error_code)
51
using namespace testing;
53
EXPECT_CALL(mock_egl, eglGetError())
54
.WillOnce(Return(egl_error_code));
60
throw mg::egl_error("");
62
catch (std::system_error const& error)
67
EXPECT_THAT(ec.value(), Eq(egl_error_code));
70
TEST_F(EGLErrorTest, produces_message_with_user_string_and_error_code_for_known_error)
72
using namespace testing;
74
EXPECT_CALL(mock_egl, eglGetError())
75
.WillOnce(Return(egl_error_code));
77
std::string error_message;
81
throw mg::egl_error(user_message);
83
catch (std::system_error const& error)
85
error_message = error.what();
88
EXPECT_THAT(error_message, HasSubstr(user_message));
89
EXPECT_THAT(error_message, HasSubstr(egl_error_code_str));
90
EXPECT_THAT(error_message, HasSubstr(to_hex_string(egl_error_code)));
93
TEST_F(EGLErrorTest, produces_message_with_user_string_and_error_code_for_unknown_error)
95
using namespace testing;
97
int const unknown_egl_error_code{0x131313};
99
EXPECT_CALL(mock_egl, eglGetError())
100
.WillOnce(Return(unknown_egl_error_code));
102
std::string error_message;
106
throw mg::egl_error(user_message);
108
catch (std::system_error const& error)
110
error_message = error.what();
113
EXPECT_THAT(error_message, HasSubstr(user_message));
114
EXPECT_THAT(error_message, HasSubstr(to_hex_string(unknown_egl_error_code)));