mirror of
https://github.com/google/pebble.git
synced 2025-05-20 10:24:58 +00:00
Import of the watch repository from Pebble
This commit is contained in:
commit
3b92768480
10334 changed files with 2564465 additions and 0 deletions
96
tests/fw/applib/test_bitmap_layer.c
Normal file
96
tests/fw/applib/test_bitmap_layer.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright 2024 Google LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "clar.h"
|
||||
|
||||
#include "applib/graphics/graphics.h"
|
||||
#include "applib/ui/bitmap_layer.h"
|
||||
|
||||
// Stubs
|
||||
/////////////////////
|
||||
#include "stubs_app_state.h"
|
||||
#include "stubs_graphics.h"
|
||||
#include "stubs_graphics_context.h"
|
||||
#include "stubs_heap.h"
|
||||
#include "stubs_logging.h"
|
||||
#include "stubs_passert.h"
|
||||
#include "stubs_pbl_malloc.h"
|
||||
#include "stubs_pebble_tasks.h"
|
||||
#include "stubs_resources.h"
|
||||
#include "stubs_syscalls.h"
|
||||
#include "stubs_ui_window.h"
|
||||
#include "stubs_unobstructed_area.h"
|
||||
|
||||
// Fakes
|
||||
/////////////////////
|
||||
|
||||
static GRect s_graphics_draw_bitmap_in_rect__rect = GRectZero;
|
||||
|
||||
void graphics_draw_bitmap_in_rect(GContext* ctx, const GBitmap *src_bitmap, const GRect *rect) {
|
||||
s_graphics_draw_bitmap_in_rect__rect = *rect;
|
||||
}
|
||||
|
||||
bool process_manager_compiled_with_legacy2_sdk(void) {
|
||||
return cl_mock_type(bool);
|
||||
}
|
||||
|
||||
// Test boilerplate
|
||||
/////////////////////
|
||||
|
||||
void test_bitmap_layer__initialize(void) {
|
||||
}
|
||||
|
||||
void test_bitmap_layer__cleanup(void) {
|
||||
}
|
||||
|
||||
// Tests
|
||||
//////////////////////
|
||||
|
||||
// Test inspired by PBL-19136. Check that bitmaps get drawn in the right rect
|
||||
// on recent SDKs but that a previous bug is kept for 2.x SDK
|
||||
void test_bitmap_layer__nonzero_bounds(void) {
|
||||
GContext ctx = {
|
||||
.draw_state = (GDrawState) {
|
||||
.clip_box = GRect(0, 0, 144, 168),
|
||||
.drawing_box = GRect(0, 0, 144, 168),
|
||||
},
|
||||
};
|
||||
|
||||
static const GRect BITMAP_LAYER_FRAME = GRect(0, 0, 640, 64);
|
||||
static const GRect BITMAP_LAYER_BOUNDS = GRect(-32, 0, 640, 64);
|
||||
static const GRect BITMAP_BOUNDS = GRect(0, 0, 640, 64);
|
||||
GBitmap bitmap = {
|
||||
.bounds = BITMAP_BOUNDS,
|
||||
};
|
||||
|
||||
BitmapLayer layer;
|
||||
bitmap_layer_init(&layer, &BITMAP_LAYER_FRAME);
|
||||
bitmap_layer_set_bitmap(&layer, &bitmap);
|
||||
|
||||
// set bounds with non-zero origin
|
||||
layer_set_bounds((Layer *)&layer, &BITMAP_LAYER_BOUNDS);
|
||||
|
||||
// !legacy2
|
||||
cl_will_return(process_manager_compiled_with_legacy2_sdk, false);
|
||||
layer_render_tree((Layer *)&layer, &ctx);
|
||||
GRect expected_rect = BITMAP_BOUNDS;
|
||||
cl_assert(grect_equal(&s_graphics_draw_bitmap_in_rect__rect, &expected_rect));
|
||||
// legacy2
|
||||
cl_will_return(process_manager_compiled_with_legacy2_sdk, true);
|
||||
layer_render_tree((Layer *)&layer, &ctx);
|
||||
expected_rect = BITMAP_LAYER_BOUNDS;
|
||||
cl_assert(grect_equal(&s_graphics_draw_bitmap_in_rect__rect, &expected_rect));
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue