Import of the watch repository from Pebble

This commit is contained in:
Matthieu Jeanson
2024-12-12 16:43:03 -08:00
committed by Katharine Berry
commit 3b92768480
10334 changed files with 2564465 additions and 0 deletions

View File

@@ -0,0 +1,595 @@
/*
* 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 "apps/system_apps/workout/workout.h"
#include "apps/system_apps/workout/workout_active.h"
#include "apps/system_apps/workout/workout_data.h"
#include "apps/system_apps/workout/workout_dialog.h"
#include "services/normal/activity/health_util.h"
#include "test_workout_app_includes.h"
#include "stubs_window_manager.h"
bool s_hrm_is_present;
// Fakes
/////////////////////
extern void prv_cycle_scrollable_metrics(WorkoutActiveWindow *active_window);
bool activity_is_hrm_present(void) {
return s_hrm_is_present;
}
uint16_t time_ms(time_t *tloc, uint16_t *out_ms) {
return 0;
}
void workout_push_summary_window(void) {
return;
}
static WorkoutData s_workout_data;
static WorkoutController s_workout_controller = {
.is_paused = workout_service_is_paused,
.pause = workout_service_pause_workout,
.stop = workout_service_stop_workout,
.update_data = workout_data_update,
.metric_to_string = workout_data_fill_metric_value,
.get_metric_value = workout_data_get_metric_value,
.get_distance_string = health_util_get_distance_string,
};
typedef struct SportsData {
int32_t current_bpm;
char *duration_string;
char *distance_string;
char *pace_string;
char *custom_label_string;
char *custom_value_string;
} SportsData;
static SportsData s_sports_data;
static bool prv_is_sports_paused(void) { return false; }
static bool prv_sports_pause(bool should_be_paused) { return false; }
static void prv_metric_to_string(WorkoutMetricType type, char *buffer, size_t buffer_size,
void *i18n_owner, void *sports_data) {
SportsData *data = sports_data;
switch (type) {
case WorkoutMetricType_Hr:
{
snprintf(buffer, buffer_size, "%d", data->current_bpm);
break;
}
case WorkoutMetricType_Speed:
case WorkoutMetricType_Pace:
{
strncpy(buffer, data->pace_string, buffer_size);
break;
}
case WorkoutMetricType_Distance:
{
strncpy(buffer, data->distance_string, buffer_size);
break;
}
case WorkoutMetricType_Duration:
{
strncpy(buffer, data->duration_string, buffer_size);
break;
}
case WorkoutMetricType_Custom:
{
strncpy(buffer, data->custom_value_string, buffer_size);
break;
}
// Not supported by the sports API
case WorkoutMetricType_Steps:
case WorkoutMetricType_AvgPace:
case WorkoutMetricType_None:
case WorkoutMetricTypeCount:
break;
}
}
static int32_t prv_sports_get_value(WorkoutMetricType type, void *sports_data) {
SportsData *data = sports_data;
switch (type) {
case WorkoutMetricType_Hr:
return data->current_bpm;
default:
return 0;
}
}
static char *prv_get_custom_metric_label_string(void) {
return s_sports_data.custom_label_string;
}
static WorkoutController s_sports_controller = {
.is_paused = prv_is_sports_paused,
.pause = prv_sports_pause,
.stop = NULL,
.update_data = NULL,
.metric_to_string = prv_metric_to_string,
.get_metric_value = prv_sports_get_value,
.get_distance_string = health_util_get_distance_string,
.get_custom_metric_label_string = prv_get_custom_metric_label_string,
};
// Setup and Teardown
////////////////////////////////////
static GContext s_ctx;
static FrameBuffer s_fb;
GContext *graphics_context_get_current_context(void) {
return &s_ctx;
}
void test_workout_active__initialize(void) {
s_hrm_is_present = true;
s_workout_data = (WorkoutData) {};
s_sports_data = (SportsData) {};
// Setup graphics context
framebuffer_init(&s_fb, &(GSize) {DISP_COLS, DISP_ROWS});
framebuffer_clear(&s_fb);
graphics_context_init(&s_ctx, &s_fb, GContextInitializationMode_App);
s_app_state_get_graphics_context = &s_ctx;
// Setup resources
fake_spi_flash_init(0 /* offset */, 0x1000000 /* length */);
pfs_init(false /* run filesystem check */);
pfs_format(true /* write erase headers */);
load_resource_fixture_in_flash(RESOURCES_FIXTURE_PATH, SYSTEM_RESOURCES_FIXTURE_NAME,
false /* is_next */);
resource_init();
// Setup content indicator
ContentIndicatorsBuffer *buffer = content_indicator_get_current_buffer();
content_indicator_init_buffer(buffer);
}
void test_workout_active__cleanup(void) {
}
// Helpers
//////////////////////
static void prv_create_window_and_render(WorkoutActiveWindow *active_window,
int seconday_metric_idx) {
for (int i = 0; i < seconday_metric_idx; i++) {
prv_cycle_scrollable_metrics(active_window);
}
Window *window = (Window *)active_window;
window_set_on_screen(window, true, true);
window_render(window, &s_ctx);
}
// Workout Tests
//////////////////////
void test_workout_active__workout_render_no_data(void) {
s_workout_data = (WorkoutData) {};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Run, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_walk(void) {
s_workout_data = (WorkoutData) {
.steps = 567,
.duration_s = 84,
.distance_m = 1234,
.avg_pace = health_util_get_pace(84, 1234),
.bpm = 71,
.hr_zone = 0,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Walk, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_walk_no_hrm(void) {
s_hrm_is_present = false;
s_workout_data = (WorkoutData) {
.steps = 567,
.duration_s = 84,
.distance_m = 1234,
.avg_pace = health_util_get_pace(84, 1234),
.bpm = 71,
.hr_zone = 0,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Walk, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_run(void) {
s_workout_data = (WorkoutData) {
.steps = 567,
.duration_s = 84,
.distance_m = 1234,
.avg_pace = health_util_get_pace(84, 1234),
.bpm = 71,
.hr_zone = 0,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Run, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_run_no_hrm(void) {
s_hrm_is_present = false;
s_workout_data = (WorkoutData) {
.steps = 567,
.duration_s = 84,
.distance_m = 1234,
.avg_pace = health_util_get_pace(84, 1234),
.bpm = 71,
.hr_zone = 0,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Run, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_open_workout(void) {
s_workout_data = (WorkoutData) {
.steps = 0,
.duration_s = 84,
.distance_m = 0,
.avg_pace = health_util_get_pace(84, 0),
.bpm = 92,
.hr_zone = 0,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Open, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_open_workout_no_hrm(void) {
s_hrm_is_present = false;
s_workout_data = (WorkoutData) {
.steps = 0,
.duration_s = 84,
.distance_m = 0,
.avg_pace = health_util_get_pace(84, 0),
.bpm = 92,
.hr_zone = 0,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Open, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_hr_zone_1(void) {
s_workout_data = (WorkoutData) {
.steps = 567,
.duration_s = 789,
.distance_m = 234,
.avg_pace = health_util_get_pace(789, 234),
.bpm = 148,
.hr_zone = 1,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Run, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_hr_zone_2(void) {
s_workout_data = (WorkoutData) {
.steps = 567,
.duration_s = 789,
.distance_m = 234,
.avg_pace = health_util_get_pace(789, 234),
.bpm = 167,
.hr_zone = 2,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Run, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_hr_zone_3(void) {
s_workout_data = (WorkoutData) {
.steps = 567,
.duration_s = 789,
.distance_m = 234,
.avg_pace = health_util_get_pace(789, 234),
.bpm = 197,
.hr_zone = 3,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Run, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__workout_render_very_slow_pace(void) {
s_workout_data = (WorkoutData) {
.steps = 0,
.duration_s = SECONDS_PER_HOUR,
.distance_m = 1609,
.avg_pace = health_util_get_pace(SECONDS_PER_HOUR, 1609),
.bpm = 0,
.hr_zone = 0,
};
WorkoutActiveWindow *active_window = workout_active_create_for_activity_type(
ActivitySessionType_Walk, &s_workout_data, &s_workout_controller);
prv_create_window_and_render(active_window, 2);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
// Workout Tests
//////////////////////
void test_workout_active__sports_pace(void) {
s_sports_data = (SportsData) {
.current_bpm = 71,
.duration_string = "30:00",
.distance_string = "5.0",
.pace_string = "6:00",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace,
WorkoutMetricType_Hr};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_pace_long_values(void) {
s_sports_data = (SportsData) {
.current_bpm = 71,
.duration_string = "04:20:39",
.distance_string = "115.12",
.pace_string = "12:34",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace,
WorkoutMetricType_Hr};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_speed(void) {
s_sports_data = (SportsData) {
.current_bpm = 71,
.duration_string = "20:00",
.distance_string = "18.9",
.pace_string = "35.3",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Speed,
WorkoutMetricType_Hr};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_no_hrm(void) {
s_hrm_is_present = false;
s_sports_data = (SportsData) {
.current_bpm = 71,
.duration_string = "30:00",
.distance_string = "5.0",
.pace_string = "6:00",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_hr_z0(void) {
s_sports_data = (SportsData) {
.current_bpm = 71,
.duration_string = "30:00",
.distance_string = "5.0",
.pace_string = "6:00",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace,
WorkoutMetricType_Hr};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 1);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_hr_z1(void) {
s_sports_data = (SportsData) {
.current_bpm = 135,
.duration_string = "30:00",
.distance_string = "5.0",
.pace_string = "6:00",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace,
WorkoutMetricType_Hr};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 1);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_hr_z2(void) {
s_sports_data = (SportsData) {
.current_bpm = 165,
.duration_string = "30:00",
.distance_string = "5.0",
.pace_string = "6:00",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace,
WorkoutMetricType_Hr};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 1);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_hr_z3(void) {
s_sports_data = (SportsData) {
.current_bpm = 180,
.duration_string = "30:00",
.distance_string = "5.0",
.pace_string = "6:00",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace,
WorkoutMetricType_Hr};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 1);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_custom_field(void) {
s_sports_data = (SportsData) {
.current_bpm = 71,
.duration_string = "30:00",
.distance_string = "5.0",
.pace_string = "6:00",
.custom_label_string = "CUSTOM",
.custom_value_string = "000000",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace,
WorkoutMetricType_Custom};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 1);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_custom_long_values(void) {
s_sports_data = (SportsData) {
.current_bpm = 71,
.duration_string = "30:00",
.distance_string = "5.0",
.pace_string = "6:00",
.custom_label_string = "CUSTOM FIELD LABEL",
.custom_value_string = "0000000000000000000",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace,
WorkoutMetricType_Custom};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 1);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_active__sports_custom_hanging_label(void) {
s_sports_data = (SportsData) {
.current_bpm = 71,
.duration_string = "30:00",
.distance_string = "5.0",
.pace_string = "6:00",
.custom_label_string = "Hanging Field",
.custom_value_string = "000000",
};
WorkoutMetricType top_metric = WorkoutMetricType_Duration;
WorkoutMetricType middle_metric = WorkoutMetricType_Distance;
WorkoutMetricType scrollable_metrics[] = {WorkoutMetricType_Pace,
WorkoutMetricType_Custom};
WorkoutActiveWindow *active_window = workout_active_create_tripple_layout(
top_metric, middle_metric, ARRAY_LENGTH(scrollable_metrics), scrollable_metrics,
&s_sports_data, &s_sports_controller);
prv_create_window_and_render(active_window, 1);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}

View File

@@ -0,0 +1,86 @@
/*
* 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 "applib/ui/window_private.h"
#include "util/size.h"
#include "clar.h"
// Fakes
/////////////////////
#include "fake_content_indicator.h"
#include "fake_rtc.h"
#include "fake_pbl_std.h"
#include "fake_regular_timer.h"
#include "fake_spi_flash.h"
#include "fake_workout_service.h"
#include "fixtures/load_test_resources.h"
// Stubs
/////////////////////
#include "stubs_activity.h"
#include "stubs_action_menu.h"
#include "stubs_analytics.h"
#include "stubs_animation_timing.h"
#include "stubs_app_install_manager.h"
#include "stubs_app_timer.h"
#include "stubs_app_window_stack.h"
#include "stubs_attribute.h"
#include "stubs_bootbits.h"
#include "stubs_click.h"
#include "stubs_event_service_client.h"
#include "stubs_health_service.h"
#include "stubs_i18n.h"
#include "stubs_layer.h"
#include "stubs_logging.h"
#include "stubs_memory_layout.h"
#include "stubs_mutex.h"
#include "stubs_notifications.h"
#include "stubs_passert.h"
#include "stubs_pbl_malloc.h"
#include "stubs_pebble_process_info.h"
#include "stubs_pebble_tasks.h"
#include "stubs_process_manager.h"
#include "stubs_prompt.h"
#include "stubs_serial.h"
#include "stubs_shell_prefs.h"
#include "stubs_sleep.h"
#include "stubs_syscalls.h"
#include "stubs_task_watchdog.h"
#include "stubs_timeline_item.h"
#include "stubs_vibes.h"
#include "stubs_window_manager.h"
#include "stubs_window_stack.h"
typedef struct KinoReel KinoReel;
KinoReel *kino_reel_scale_segmented_create(KinoReel *from_reel, bool take_ownership,
GRect screen_frame) {
return NULL;
}
void kino_reel_scale_segmented_set_deflate_effect(KinoReel *reel, int16_t expand) {}
bool kino_reel_scale_segmented_set_delay_by_distance(KinoReel *reel, GPoint target) {
return false;
}
// Helper Functions
/////////////////////
#include "fw/graphics/util.h"

View File

@@ -0,0 +1,122 @@
/*
* 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 "apps/system_apps/workout/workout_dialog.h"
#include "resource/resource_ids.auto.h"
#include "test_workout_app_includes.h"
// Fakes
/////////////////////
uint16_t time_ms(time_t *tloc, uint16_t *out_ms) {
return 0;
}
// Setup and Teardown
////////////////////////////////////
static GContext s_ctx;
static FrameBuffer s_fb;
GContext *graphics_context_get_current_context(void) {
return &s_ctx;
}
void test_workout_dialog__initialize(void) {
// Setup graphics context
framebuffer_init(&s_fb, &(GSize) {DISP_COLS, DISP_ROWS});
framebuffer_clear(&s_fb);
graphics_context_init(&s_ctx, &s_fb, GContextInitializationMode_App);
s_app_state_get_graphics_context = &s_ctx;
// Setup resources
fake_spi_flash_init(0 /* offset */, 0x1000000 /* length */);
pfs_init(false /* run filesystem check */);
pfs_format(true /* write erase headers */);
load_resource_fixture_in_flash(RESOURCES_FIXTURE_PATH, SYSTEM_RESOURCES_FIXTURE_NAME,
false /* is_next */);
resource_init();
// Setup content indicator
ContentIndicatorsBuffer *buffer = content_indicator_get_current_buffer();
content_indicator_init_buffer(buffer);
}
void test_workout_dialog__cleanup(void) {
}
// Tests
//////////////////////
void test_workout_dialog__render_end_workout(void) {
WorkoutDialog *workout_dialog = workout_dialog_create("Workout End");
Dialog *dialog = workout_dialog_get_dialog(workout_dialog);
dialog_show_status_bar_layer(dialog, true);
dialog_set_fullscreen(dialog, true);
dialog_set_text(dialog, "End Workout?");
dialog_set_background_color(dialog, PBL_IF_COLOR_ELSE(GColorYellow, GColorWhite));
dialog_set_text_color(dialog, GColorBlack);
dialog_set_icon(dialog, RESOURCE_ID_WORKOUT_APP_END);
dialog_set_icon_animate_direction(dialog, DialogIconAnimateNone);
window_set_on_screen(&dialog->window, true, true);
window_render(&dialog->window, &s_ctx);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_dialog__render_detected_workout(void) {
WorkoutDialog *workout_dialog = workout_dialog_create("Workout Detected");
Dialog *dialog = workout_dialog_get_dialog(workout_dialog);
dialog_show_status_bar_layer(dialog, true);
dialog_set_fullscreen(dialog, true);
dialog_set_background_color(dialog, PBL_IF_COLOR_ELSE(GColorYellow, GColorWhite));
dialog_set_text_color(dialog, GColorBlack);
dialog_set_icon(dialog, RESOURCE_ID_WORKOUT_APP_DETECTED);
dialog_set_icon_animate_direction(dialog, DialogIconAnimateNone);
workout_dialog_set_text(workout_dialog, "Run\nDetected");
workout_dialog_set_subtext(workout_dialog, "03:42");
window_set_on_screen(&dialog->window, true, true);
window_render(&dialog->window, &s_ctx);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_dialog__render_workout_ended(void) {
WorkoutDialog *workout_dialog = workout_dialog_create("Workout Ended");
Dialog *dialog = workout_dialog_get_dialog(workout_dialog);
dialog_show_status_bar_layer(dialog, true);
dialog_set_fullscreen(dialog, true);
dialog_set_background_color(dialog, PBL_IF_COLOR_ELSE(GColorYellow, GColorWhite));
dialog_set_text_color(dialog, GColorBlack);
dialog_set_icon(dialog, RESOURCE_ID_WORKOUT_APP_DETECTED);
dialog_set_icon_animate_direction(dialog, DialogIconAnimateNone);
workout_dialog_set_text(workout_dialog, "Workout\nEnded");
workout_dialog_set_action_bar_hidden(workout_dialog, true);
window_set_on_screen(&dialog->window, true, true);
window_render(&dialog->window, &s_ctx);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}

View File

@@ -0,0 +1,102 @@
/*
* 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 "apps/system_apps/workout/workout_selection.h"
#include "test_workout_app_includes.h"
typedef struct WorkoutSelectionWindow {
Window window;
MenuLayer menu_layer;
} WorkoutSelectionWindow;
// Fakes
/////////////////////
uint16_t time_ms(time_t *tloc, uint16_t *out_ms) {
return 0;
}
bool workout_service_is_workout_type_supported(ActivitySessionType type) {
return true;
}
// Setup and Teardown
////////////////////////////////////
static GContext s_ctx;
static FrameBuffer s_fb;
GContext *graphics_context_get_current_context(void) {
return &s_ctx;
}
void test_workout_selection__initialize(void) {
// Setup graphics context
framebuffer_init(&s_fb, &(GSize) {DISP_COLS, DISP_ROWS});
framebuffer_clear(&s_fb);
graphics_context_init(&s_ctx, &s_fb, GContextInitializationMode_App);
s_app_state_get_graphics_context = &s_ctx;
// Setup resources
fake_spi_flash_init(0 /* offset */, 0x1000000 /* length */);
pfs_init(false /* run filesystem check */);
pfs_format(true /* write erase headers */);
load_resource_fixture_in_flash(RESOURCES_FIXTURE_PATH, SYSTEM_RESOURCES_FIXTURE_NAME,
false /* is_next */);
resource_init();
// Setup content indicator
ContentIndicatorsBuffer *buffer = content_indicator_get_current_buffer();
content_indicator_init_buffer(buffer);
}
void test_workout_selection__cleanup(void) {
}
// Helpers
//////////////////////
static void prv_select_workout_cb(ActivitySessionType type) { }
static void prv_create_window_and_render(uint16_t row) {
WorkoutSelectionWindow *selection_window = workout_selection_push(prv_select_workout_cb);
Window *window = &selection_window->window;
MenuLayer *menu_layer = &selection_window->menu_layer;
menu_layer_set_selected_index(menu_layer, MenuIndex(0, row), MenuRowAlignCenter, false);
window_set_on_screen(window, true, true);
window_render(window, &s_ctx);
}
// Tests
//////////////////////
void test_workout_selection__render_run_selected(void) {
prv_create_window_and_render(0);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_selection__render_walk_selected(void) {
prv_create_window_and_render(1);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_selection__render_workout_selected(void) {
prv_create_window_and_render(2);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}

View 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 "apps/system_apps/workout/workout_summary.h"
#include "apps/system_apps/workout/workout_utils.h"
#include "test_workout_app_includes.h"
// Fakes
/////////////////////
uint16_t time_ms(time_t *tloc, uint16_t *out_ms) {
return 0;
}
bool workout_service_is_workout_type_supported(ActivitySessionType type) {
return true;
}
// Setup and Teardown
////////////////////////////////////
static GContext s_ctx;
static FrameBuffer s_fb;
GContext *graphics_context_get_current_context(void) {
return &s_ctx;
}
void test_workout_summary__initialize(void) {
// Setup graphics context
framebuffer_init(&s_fb, &(GSize) {DISP_COLS, DISP_ROWS});
framebuffer_clear(&s_fb);
graphics_context_init(&s_ctx, &s_fb, GContextInitializationMode_App);
s_app_state_get_graphics_context = &s_ctx;
// Setup resources
fake_spi_flash_init(0 /* offset */, 0x1000000 /* length */);
pfs_init(false /* run filesystem check */);
pfs_format(true /* write erase headers */);
load_resource_fixture_in_flash(RESOURCES_FIXTURE_PATH, SYSTEM_RESOURCES_FIXTURE_NAME,
false /* is_next */);
resource_init();
// Setup content indicator
ContentIndicatorsBuffer *buffer = content_indicator_get_current_buffer();
content_indicator_init_buffer(buffer);
}
void test_workout_summary__cleanup(void) {
}
// Helpers
//////////////////////
static void prv_start_workout_cb(ActivitySessionType type) { }
static void prv_select_workout_cb(ActivitySessionType type) { }
static void prv_create_window_and_render(ActivitySessionType activity_type) {
Window *window = (Window *)workout_summary_window_create(activity_type,
prv_start_workout_cb,
prv_select_workout_cb);
window_set_on_screen(window, true, true);
window_render(window, &s_ctx);
}
// Tests
//////////////////////
void test_workout_summary__render_open_workout(void) {
prv_create_window_and_render(ActivitySessionType_Open);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_summary__render_walk(void) {
prv_create_window_and_render(ActivitySessionType_Walk);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}
void test_workout_summary__render_run(void) {
prv_create_window_and_render(ActivitySessionType_Run);
cl_check(gbitmap_pbi_eq(&s_ctx.dest_bitmap, TEST_PBI_FILE));
}

View File

@@ -0,0 +1,109 @@
/*
* 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 "apps/system_apps/workout/workout_utils.h"
#include "clar.h"
#include "services/normal/activity/activity.h"
// ---------------------------------------------------------------------------------------
#include "stubs_attribute.h"
#include "stubs_i18n.h"
#include "stubs_notifications.h"
#include "stubs_passert.h"
#include "stubs_pbl_malloc.h"
#include "stubs_rtc.h"
#include "stubs_timeline_item.h"
// Stubs
///////////////////////////////////////////////////////////
bool workout_service_is_workout_type_supported(ActivitySessionType type) {
return true;
}
// Fakes
///////////////////////////////////////////////////////////
static ActivitySession s_sessions[ACTIVITY_MAX_ACTIVITY_SESSIONS_COUNT];
static uint32_t s_num_sessions = 0;
static void prv_add_session(ActivitySession *session) {
memcpy(&s_sessions[s_num_sessions++], session, sizeof(ActivitySession));
}
// ---------------------------------------------------------------------------------------
bool activity_get_sessions(uint32_t *session_entries, ActivitySession *sessions) {
memcpy(sessions, s_sessions, s_num_sessions * sizeof(ActivitySession));
*session_entries = s_num_sessions;
return true;
}
// ---------------------------------------------------------------------------------------
void test_workout_utils__initialize(void) {
s_num_sessions = 0;
}
void test_workout_utils__cleanup(void) {
}
// ---------------------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------------------
void test_workout_utils__find_ongoing_activity_session(void) {
bool found_session;
// Check if it can handle NULL session
found_session = workout_utils_find_ongoing_activity_session(NULL);
cl_assert_equal_b(found_session, false);
// Make sure there are no sessions
cl_assert_equal_i(s_num_sessions, 0);
// Add a non-ongoing walk session
prv_add_session(&(ActivitySession){
.type = ActivitySessionType_Walk,
.ongoing = false,
});
// Make sure the session was added
cl_assert_equal_i(s_num_sessions, 1);
// Find the session we just added
ActivitySession walk_session = {};
found_session = workout_utils_find_ongoing_activity_session(&walk_session);
// Made sure non-ongoing sessions are not returned
cl_assert_equal_b(found_session, false);
// Add an ongoing run session
prv_add_session(&(ActivitySession){
.type = ActivitySessionType_Run,
.ongoing = true,
});
// Make sure the session was added
cl_assert_equal_i(s_num_sessions, 2);
// Find the session we just added
ActivitySession run_session = {};
found_session = workout_utils_find_ongoing_activity_session(&run_session);
// Make sure the function returned true and the returned session is of type run
cl_assert_equal_b(found_session, true);
cl_assert_equal_i(run_session.type, ActivitySessionType_Run);
}

View File

@@ -0,0 +1,155 @@
from waftools.pebble_test import clar
def build(ctx):
rendering_sources = \
" src/fw/applib/fonts/codepoint.c" \
" src/fw/applib/graphics/${BITDEPTH}_bit/framebuffer.c" \
" src/fw/applib/graphics/${BITDEPTH}_bit/bitblt_private.c" \
" src/fw/applib/graphics/bitblt.c" \
" src/fw/applib/graphics/framebuffer.c" \
" src/fw/applib/graphics/gbitmap.c" \
" src/fw/applib/graphics/gbitmap_png.c" \
" src/fw/applib/graphics/gbitmap_sequence.c" \
" src/fw/applib/graphics/gcolor_definitions.c" \
" src/fw/applib/graphics/gdraw_command.c" \
" src/fw/applib/graphics/gdraw_command_frame.c" \
" src/fw/applib/graphics/gdraw_command_image.c" \
" src/fw/applib/graphics/gdraw_command_list.c" \
" src/fw/applib/graphics/gdraw_command_sequence.c" \
" src/fw/applib/graphics/gpath.c" \
" src/fw/applib/graphics/graphics.c" \
" src/fw/applib/graphics/graphics_bitmap.c" \
" src/fw/applib/graphics/graphics_circle.c" \
" src/fw/applib/graphics/graphics_line.c" \
" src/fw/applib/graphics/graphics_private.c" \
" src/fw/applib/graphics/graphics_private_raw.c" \
" src/fw/applib/graphics/gtransform.c" \
" src/fw/applib/graphics/gtypes.c" \
" src/fw/applib/graphics/perimeter.c" \
" src/fw/applib/graphics/text_layout.c" \
" src/fw/applib/graphics/text_render.c" \
" src/fw/applib/graphics/text_resources.c" \
" src/fw/applib/graphics/utf8.c" \
" src/fw/applib/ui/action_bar_layer.c" \
" src/fw/applib/ui/status_bar_layer.c" \
" src/fw/applib/ui/kino/kino_reel.c" \
" src/fw/applib/ui/kino/kino_reel_gbitmap.c" \
" src/fw/applib/ui/kino/kino_reel_gbitmap_sequence.c" \
" src/fw/applib/ui/kino/kino_reel_pdci.c" \
" src/fw/applib/ui/kino/kino_reel_pdcs.c" \
" src/fw/applib/ui/layer.c" \
" src/fw/applib/ui/menu_layer_system_cells.c" \
" src/fw/applib/vendor/tinflate/tinflate.c" \
" src/fw/applib/vendor/uPNG/upng.c" \
" src/fw/board/displays/display_spalding.c" \
" src/fw/drivers/flash/flash_crc.c" \
" src/fw/flash_region/filesystem_regions.c" \
" src/fw/flash_region/flash_region.c" \
" src/fw/resource/resource.c" \
" src/fw/resource/resource_storage.c" \
" src/fw/resource/resource_storage_builtin.c" \
" src/fw/resource/resource_storage_file.c" \
" src/fw/resource/resource_storage_flash.c" \
" src/fw/services/normal/filesystem/app_file.c" \
" src/fw/services/normal/filesystem/flash_translation.c" \
" src/fw/services/normal/filesystem/pfs.c" \
" src/fw/system/hexdump.c" \
" src/fw/util/crc8.c" \
" src/fw/util/legacy_checksum.c" \
" tests/fakes/fake_applib_resource.c" \
" tests/fakes/fake_display.c" \
" tests/fakes/fake_gbitmap_get_data_row.c" \
" tests/fakes/fake_rtc.c" \
" tests/fakes/fake_spi_flash.c" \
" tests/fixtures/resources/builtin_resources.auto.c" \
" tests/fixtures/resources/pfs_resource_table.c" \
" tests/stubs/stubs_animation.c" \
" tests/stubs/stubs_system_theme.c"
workout_app_sources = \
" src/fw/applib/graphics/gpath_builder.c" \
" src/fw/applib/ui/animation_interpolate.c" \
" src/fw/applib/ui/content_indicator.c" \
" src/fw/applib/ui/dialogs/dialog.c" \
" src/fw/applib/ui/dialogs/dialog_private.c" \
" src/fw/applib/ui/inverter_layer.c" \
" src/fw/applib/ui/kino/kino_layer.c" \
" src/fw/applib/ui/kino/kino_player.c" \
" src/fw/applib/ui/kino/kino_reel/transform.c" \
" src/fw/applib/ui/kino/kino_reel_custom.c" \
" src/fw/applib/ui/scroll_layer.c" \
" src/fw/applib/ui/shadows.c" \
" src/fw/applib/ui/text_layer.c" \
" src/fw/applib/ui/text_layer_flow.c" \
" src/fw/applib/ui/window.c" \
" src/fw/apps/system_apps/timeline/text_node.c" \
" src/fw/services/normal/activity/health_util.c" \
" src/fw/services/normal/activity/hr_util.c" \
" src/fw/services/normal/timeline/timeline_resources.c" \
" src/fw/util/buffer.c" \
" src/fw/util/stats.c" \
" src/fw/util/time/mktime.c" \
" src/fw/util/time/time.c" \
" tests/fakes/fake_clock.c" \
" tests/fakes/fake_fonts.c" \
" tests/fakes/fake_workout_service.c" \
" tests/fixtures/resources/timeline_resource_table.auto.c"
clar(ctx,
sources_ant_glob = rendering_sources + \
workout_app_sources + \
" src/fw/applib/ui/menu_layer.c" \
" src/fw/apps/system_apps/workout/workout_countdown.c" + \
" src/fw/apps/system_apps/workout/workout_selection.c" + \
" src/fw/apps/system_apps/workout/workout_dialog.c" + \
" src/fw/apps/system_apps/workout/workout_utils.c" + \
" src/fw/apps/system_apps/workout/workout_summary.c",
test_sources_ant_glob = "test_workout_summary.c",
defines=ctx.env.test_image_defines + ["USE_DISPLAY_PERIMETER_ON_FONT_LAYOUT=1"],
runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis + ctx.env.test_pfos,
override_includes=['dummy_board'],
platforms=['snowy', 'spalding', 'silk'])
clar(ctx,
sources_ant_glob = rendering_sources + \
workout_app_sources + \
" src/fw/applib/ui/menu_layer.c" \
" src/fw/apps/system_apps/workout/workout_data.c" + \
" src/fw/apps/system_apps/workout/workout_dialog.c" + \
" src/fw/apps/system_apps/workout/workout_active.c",
test_sources_ant_glob = "test_workout_active.c",
defines=ctx.env.test_image_defines + ["USE_DISPLAY_PERIMETER_ON_FONT_LAYOUT=1"],
runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis + ctx.env.test_pfos,
override_includes=['dummy_board'],
platforms=['snowy', 'spalding', 'silk'])
clar(ctx,
sources_ant_glob = rendering_sources + \
workout_app_sources + \
" src/fw/applib/ui/menu_layer.c" \
" src/fw/apps/system_apps/workout/workout_data.c" + \
" src/fw/apps/system_apps/workout/workout_dialog.c",
test_sources_ant_glob = "test_workout_dialog.c",
defines=ctx.env.test_image_defines + ["USE_DISPLAY_PERIMETER_ON_FONT_LAYOUT=1"],
runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis + ctx.env.test_pfos,
override_includes=['dummy_board'],
platforms=['snowy', 'spalding', 'silk'])
clar(ctx,
sources_ant_glob = rendering_sources + \
workout_app_sources + \
" src/fw/applib/ui/menu_layer.c" \
" src/fw/apps/system_apps/workout/workout_utils.c" + \
" src/fw/apps/system_apps/workout/workout_selection.c",
test_sources_ant_glob = "test_workout_selection.c",
defines=ctx.env.test_image_defines + ["USE_DISPLAY_PERIMETER_ON_FONT_LAYOUT=1"],
runtime_deps=ctx.env.test_pngs + ctx.env.test_pbis + ctx.env.test_pfos,
override_includes=['dummy_board'],
platforms=['snowy', 'spalding', 'silk'])
clar(ctx,
sources_ant_glob = " src/fw/apps/system_apps/workout/workout_utils.c",
test_sources_ant_glob = "test_workout_utils.c",
override_includes=['dummy_board'])
# vim:filetype=python