why are u checking the visibility and enablelity in both functions?
Assistant
Sense::Image btnParkToLive_img = Resources::LoadIconFromResource(PARK_TO_LIVE_ENABLE_IMG);
TestUtility::GetInstance().GetButtonCustomImage(REFERENCE_HISTORY_NAVIGATION_PARK_TO_LIVE_IMAGE, testImage);
EXPECT_EQ(true, TestUtility::GetInstance().ImageCompare(testImage, btnParkToLive_img));
Sense::Image btnParkToRef1_img = Resources::LoadIconFromResource(PARK_TO_REFERENCE1_ENABLE_IMG);
TestUtility::GetInstance().GetButtonCustomImage(REFERENCE_HISTORY_NAVIGATION_PARK_TO_REFERENCE1_IMAGE, testImage);
EXPECT_EQ(true, TestUtility::GetInstance().ImageCompare(testImage, btnParkToRef1_img));
Sense::Image btnParkToRef2_img = Resources::LoadIconFromResource(PARK_TO_REFERENCE2_ENABLE_IMG);
TestUtility::GetInstance().GetButtonCustomImage(REFERENCE_HISTORY_NAVIGATION_PARK_TO_REFERENCE2_IMAGE, testImage);
EXPECT_EQ(true, TestUtility::GetInstance().ImageCompare(testImage, btnParkToRef2_img));
Sense::Image btnPreviousImage_img = Resources::LoadIconFromResource(PREVIOUS_BUTTON_ENABLE_IMG);
TestUtility::GetInstance().GetButtonCustomImage(REFERENCE_HISTORY_NAVIGATION_BTN_PREVIOUS_IMAGE, testImage);
EXPECT_EQ(true, TestUtility::GetInstance().ImageCompare(testImage, btnPreviousImage_img));
Sense::Image btnGridImageView_img = Resources::LoadIconFromResource(GRID_VIEW_ENABLE_IMG);
TestUtility::GetInstance().GetButtonCustomImage(REFERENCE_HISTORY_NAVIGATION_BTN_SINGLE_IMAGE, testImage);
EXPECT_EQ(true, TestUtility::GetInstance().ImageCompare(testImage, btnGridImageView_img));
Sense::Image btnNextImage_img = Resources::LoadIconFromResource(NEXT_BUTTON_ENABLE_IMG);
TestUtility::GetInstance().GetButtonCustomImage(REFERENCE_HISTORY_NAVIGATION_BTN_NEXT_IMAGE, testImage);
EXPECT_EQ(true, TestUtility::GetInstance().ImageCompare(testImage, btnNextImage_img));
Sense::Image RefNavigationBar_img = Resources::LoadIconFromResource(NAVIGATION_BAR_IMG);
TestUtility::GetInstance().GetImageBoxImage(REFERENCE_HISTORY_NAVIGATION_BAR_IMAGEBOX, testImage);
EXPECT_EQ(true, TestUtility::GetInstance().ImageCompare(testImage, RefNavigationBar_img));
// SingleView Position and Size testing
Rect RefHisNavigationBarPanelExpectedSize = { 530.0, 1865.0, 1330.0, 1955.0 };
Rect RefHisNavigationBarPanelActualSize = Gui::Test::TestUtility::GetInstance().GetControlBounds(REFERENCE_HISTORY_NAVIGATION_PANEL_TITLE);
EXPECT_EQ(RefHisNavigationBarPanelExpectedSize, RefHisNavigationBarPanelActualSize);
Rect RefNavigationBarExpectedSize = { 3.0, 5.0, 797.0, 85.0 };
Rect RefNavigationBarActualSize = Gui::Test::TestUtility::GetInstance().GetControlBounds(REFERENCE_HISTORY_NAVIGATION_BAR_IMAGEBOX);
EXPECT_EQ(RefNavigationBarExpectedSize, RefNavigationBarActualSize);
Rect btnParkToLiveExpectedSize = { 55.0, 5.0, 135.0, 85.0 };
Rect btnParkToLiveActualSize = Gui::Test::TestUtility::GetInstance().GetControlBounds(REFERENCE_HISTORY_NAVIGATION_PARK_TO_LIVE_IMAGE);
EXPECT_EQ(btnParkToLiveExpectedSize, btnParkToLiveActualSize);
Rect btnParkToRef1ExpectedSize = { 157.0, 5.0, 237.0, 85.0 };
Rect btnParkToRef1ActualSize = Gui::Test::TestUtility::GetInstance().GetControlBounds(REFERENCE_HISTORY_NAVIGATION_PARK_TO_REFERENCE1_IMAGE);
EXPECT_EQ(btnParkToRef1ExpectedSize, btnParkToRef1ActualSize);
Rect btnParkToRef2ExpectedSize = { 257.0, 5.0, 337.0, 85.0 };
Rect btnParkToRef2ActualSize = Gui::Test::TestUtility::GetInstance().GetControlBounds(REFERENCE_HISTORY_NAVIGATION_PARK_TO_REFERENCE2_IMAGE);
EXPECT_EQ(btnParkToRef2ExpectedSize, btnParkToRef2ActualSize);
Rect btnPreviousImgExpectedSize = { 414.0, 5.0, 494.0, 85.0 };
Rect btnPreviousImgActualSize = Gui::Test::TestUtility::GetInstance().GetControlBounds(REFERENCE_HISTORY_NAVIGATION_BTN_PREVIOUS_IMAGE);
EXPECT_EQ(btnPreviousImgExpectedSize, btnPreviousImgActualSize);
Rect btnSingleImageViewExpectedSize = { 540.0, 5.0, 620.0, 85.0 };
Rect btnSingleImageViewActualSize = Gui::Test::TestUtility::GetInstance().GetControlBounds(REFERENCE_HISTORY_NAVIGATION_BTN_SINGLE_IMAGE);
EXPECT_EQ(btnSingleImageViewExpectedSize, btnSingleImageViewActualSize);
Rect btnNextImageExpectedSize = { 665.0, 5.0, 745.0, 85.0 };
Rect btnNextImageActualSize = Gui::Test::TestUtility::GetInstance().GetControlBounds(REFERENCE_HISTORY_NAVIGATION_BTN_NEXT_IMAGE);
EXPECT_EQ(btnNextImageExpectedSize, btnNextImageActualSize);
}
void OverviewSetup()
{
GUI_SIGNAL_STRUCT signalOverlay;
signalOverlay.scType = GUI_SC_WINDOW_OVERVIEW;
int status = GUIInterface::GetInstance().IndicateSignal(MONITOR_VIEWPORT_4, 1, &signalOverlay);
EXPECT_EQ(OK, status);
}
}; this a func which is called in the below testfunc. TEST_F(ReferenceHistoryTest, ReferenceHistory_SingleView_Test)
{
ShowReferenceHistoryPanel(GUI_SINGLE_VIEW);
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(REFERENCE_HISTORY_NAVIGATION_PANEL_TITLE));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(REFERENCE_HISTORY_NAVIGATION_PANEL_TITLE));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(REFERENCE_HISTORY_NAVIGATION_PARK_TO_LIVE_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(REFERENCE_HISTORY_NAVIGATION_PARK_TO_LIVE_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(REFERENCE_HISTORY_NAVIGATION_PARK_TO_REFERENCE1_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(REFERENCE_HISTORY_NAVIGATION_PARK_TO_REFERENCE1_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(REFERENCE_HISTORY_NAVIGATION_PARK_TO_REFERENCE2_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(REFERENCE_HISTORY_NAVIGATION_PARK_TO_REFERENCE2_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(REFERENCE_HISTORY_NAVIGATION_BTN_PREVIOUS_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(REFERENCE_HISTORY_NAVIGATION_BTN_PREVIOUS_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(REFERENCE_HISTORY_NAVIGATION_BTN_SINGLE_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(REFERENCE_HISTORY_NAVIGATION_BTN_SINGLE_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(REFERENCE_HISTORY_NAVIGATION_BTN_NEXT_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(REFERENCE_HISTORY_NAVIGATION_BTN_NEXT_IMAGE));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(REFERENCE_HISTORY_NAVIGATION_BAR_IMAGEBOX));
EXPECT_FALSE(TestUtility::GetInstance().IsEnabled(REFERENCE_HISTORY_NAVIGATION_BAR_IMAGEBOX));
SingleView_UI_Verification();
HideReferenceHistoryPanel();
ASSERT_FALSE(TestUtility::GetInstance().IsVisibleSync(REFERENCE_HISTORY_NAVIGATION_PANEL_TITLE));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(REFERENCE_HISTORY_NAVIGATION_PANEL_TITLE));
} -- now i know nothing about gtest but im asked initially to write test code for the ui part of my dialog. so pls explain me in the easiest way possible am i supposed to write in the first func and what am i supposed to write in the corresponding test func.. this code is for refererence.. in my dialog i have 1 icon, 2 btns, 1 tab with 2 tab pages.. each tab page contains 1 list control.
Sure! I'll explain the basic structure and roles of the functions you posted and then tell you how you might write your own UI test code for your dialog with 1 icon, 2 buttons, 1 tab (with 2 tab pages), and lists in the tabs — in the easiest way possible.
What you have in your sample code:
SingleView_UI_Verification():
This is a helper function (not a test itself) that performs detailed UI checks, for example:
This is the actual test function that gtest will execute.
It performs:
Show the panel (your dialog or UI you want to test).
Check basic properties of controls like visibility and whether they are enabled.
Call the detailed verification helper (SingleView_UI_Verification()).
Hide the panel.
Check some properties after hiding the panel.
What gtest expects:
The TEST_F function is the "test".
You usually do setup (e.g., display your dialog), some checks/assertions, maybe call helper functions that do detailed checks for you.
You shouldn't put too many tests directly in the test function — use helper functions (like SingleView_UI_Verification) for modularity and clarity.
How to write your own test code for your dialog:
You said your dialog has:
1 Icon
2 Buttons
1 Tab control with 2 tab pages
Each tab page contains 1 list control
Step 1: Write a helper function for UI verification (MyDialog_UI_Verification())
In this function, check:
Images/Icons on buttons and icon control (compare with expected).
Verify if buttons are enabled/disabled (if that matters).
Check basic properties of the tab control, and which tab pages are visible.
Check that the lists exist on the tab pages.
Optionally, check size and position (if important).
Example pseudocode:
cpp
void MyDialog_UI_Verification()
{
Sense::Image expectedIcon = Resources::LoadIconFromResource(MY_ICON_RESOURCE);
Sense::Image actualIcon;
TestUtility::GetInstance().GetButtonCustomImage(MY_ICON_CONTROL_ID, actualIcon);
EXPECT_TRUE(TestUtility::GetInstance().ImageCompare(actualIcon, expectedIcon));
// Verify button 1
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_BUTTON1_ID));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(MY_BUTTON1_ID));
// Verify button 2
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_BUTTON2_ID));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(MY_BUTTON2_ID));
// Verify tab control visible and correct tabs present
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_TAB_CONTROL_ID));
// If possible, verify the currently selected tab page
EXPECT_EQ(TestUtility::GetInstance().GetSelectedTabIndex(MY_TAB_CONTROL_ID), 0); // for example
// Verify list control present on tab 1
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_TAB1_LIST_ID));
// Switch to tab 2 (if API available)
TestUtility::GetInstance().SelectTabPage(MY_TAB_CONTROL_ID, 1);
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_TAB2_LIST_ID));
// (Optional) Check sizes of controls if needed
Rect expectedBtn1Size = {...};
Rect actualBtn1Size = TestUtility::GetInstance().GetControlBounds(MY_BUTTON1_ID);
EXPECT_EQ(expectedBtn1Size, actualBtn1Size);
// Do similarly for others...
}
Step 2: Write the test function that will show the dialog and call verification
The TEST_F function is where you:
Show the dialog
Maybe wait for it to fully render if needed
Check basic properties of controls (visible, enabled) for sanity
Call your detailed verification helper (MyDialog_UI_Verification())
Close/hide the dialog
Check expected states after hiding (optional)
Example:
cpp
TEST_F(MyDialogTest, MyDialog_UI_Test)
{
ShowMyDialog(); // you need a function that shows your dialog
// Basic sanity checks
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_ICON_CONTROL_ID));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_BUTTON1_ID));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_BUTTON2_ID));
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_TAB_CONTROL_ID));
// Possibly check enabled as well if relevant
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(MY_BUTTON1_ID));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(MY_BUTTON2_ID));
// Call helper to do detailed verification
MyDialog_UI_Verification();
// Hide/close the dialog (you also need to implement this)
HideMyDialog();
// Confirm dialog is hidden
EXPECT_FALSE(TestUtility::GetInstance().IsVisibleSync(MY_ICON_CONTROL_ID));
}
Summary:
Function
Purpose
MyDialog_UI_Verification()
Helper: detailed UI checks (images, size, state)
TEST_F(..., TestName)
Actual test: show dialog, do basic checks, call helper, hide dialog
Tips for you as a gtest beginner:
Use EXPECT_ statements to check conditions. If an EXPECT check fails, test continues; if ASSERT_ fails, test aborts.
Organize reusable verifications in helper functions to keep tests readable.
Always do a setup: open or create your dialog/UI.
Check visibility and enabled state first (most basic).
Then add image or size checks if needed.
Finally close/hide and check cleanup.
If you want specific example code for your dialog, just share:
Control IDs/names for icon, buttons, tab control, lists.
How to show/hide dialog.
Then I can help write a sample test snippet for you.
TL;DR for your dialog:
Write a helper function to check your icon, 2 buttons, tab and lists inside tab pages.
Write a test function that opens your dialog, checks the controls are visible and enabled, calls helper, then closes dialog.
Use EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(...)) and EXPECT_EQ(...) for checks.
Feel free to ask if you want me to help you write more concrete test code based on your actual control IDs!
Great question!
Why check visibility/enabled in both the test function and the helper?
Short answer:
The test function does basic, quick sanity checks to ensure the dialog and controls are basically there and ready before doing deeper tests.
The helper function does more detailed, specific checks (like verifying images, exact sizes, states, or complex UI conditions).
They serve different purposes, and sometimes it’s helpful to check the most important things twice:
Once as a fast pre-check to avoid running detailed tests on a broken/hidden UI.
Once as part of deep validation that everything matches exactly what’s expected.
More detailed explanation:
1. In the test function (TEST_F):
You want to quickly confirm that controls are visible and enabled after showing your dialog.
This helps catch trivial problems early, e.g., dialog failed to open or controls hidden.
If these basic checks fail, you might skip the detailed checks or at least know something fundamental is off.
2. In the helper function:
You’re focusing on detailed verification of the UI state.
Sometimes you re-check visibility and enabled state to be absolutely sure before doing image comparisons or size validations.
Or you might want to check additional conditions (e.g., particular buttons are disabled, specific tabs selected, etc.) that are more complex.
Can you avoid redundant checks?
Yes, you can if your test function calls the helper only after the basic checks pass, and your helper trusts those states.
Example alternative pattern:
cpp
TEST_F(MyDialogTest, MyDialog_UI_Test)
{
ShowMyDialog();
// Basic sanity
EXPECT_TRUE(TestUtility::GetInstance().IsVisibleSync(MY_BUTTON1_ID));
EXPECT_TRUE(TestUtility::GetInstance().IsEnabled(MY_BUTTON1_ID));
if (TestUtility::GetInstance().IsVisibleSync(MY_BUTTON1_ID) &&
TestUtility::GetInstance().IsEnabled(MY_BUTTON1_ID))
{
MyDialog_UI_Verification(); // no need to re-check visibility/enabled here
}
HideMyDialog();
}
Then in MyDialog_UI_Verification() you just do detailed checks (image, size, etc.).
When is double-checking helpful?
When you have many tests sharing helper functions and some tests might call helpers with different UI states.
When your helpers are reused in different scenarios — defensive programming.
When you want immediate failures if basic properties fail (to save debugging time).
In summary:
Checking in both places offers defense in depth.
You gain clarity: test() ensures dialog opened properly, helper() focuses on detailed UI content.
You can refactor to avoid duplication if you want, but separating concerns is often clearer.
Let me know if you want me to help you refactor your test so visibility/enabled checks are only once!