| 43 | }"; |
| 44 | |
| 45 | static char* create_monitor(void) |
| 46 | { |
| 47 | const unsigned int resolution_numbers[3][2] = { |
| 48 | {1280, 720}, |
| 49 | {1920, 1080}, |
| 50 | {3840, 2160} |
| 51 | }; |
| 52 | char *string = NULL; |
| 53 | cJSON *name = NULL; |
| 54 | cJSON *resolutions = NULL; |
| 55 | cJSON *resolution = NULL; |
| 56 | cJSON *width = NULL; |
| 57 | cJSON *height = NULL; |
| 58 | size_t index = 0; |
| 59 | |
| 60 | cJSON *monitor = cJSON_CreateObject(); |
| 61 | if (monitor == NULL) |
| 62 | { |
| 63 | goto end; |
| 64 | } |
| 65 | |
| 66 | name = cJSON_CreateString("Awesome 4K"); |
| 67 | if (name == NULL) |
| 68 | { |
| 69 | goto end; |
| 70 | } |
| 71 | /* after creation was successful, immediately add it to the monitor, |
| 72 | * thereby transferring ownership of the pointer to it */ |
| 73 | cJSON_AddItemToObject(monitor, "name", name); |
| 74 | |
| 75 | resolutions = cJSON_CreateArray(); |
| 76 | if (resolutions == NULL) |
| 77 | { |
| 78 | goto end; |
| 79 | } |
| 80 | cJSON_AddItemToObject(monitor, "resolutions", resolutions); |
| 81 | |
| 82 | for (index = 0; index < (sizeof(resolution_numbers) / (2 * sizeof(int))); ++index) |
| 83 | { |
| 84 | resolution = cJSON_CreateObject(); |
| 85 | if (resolution == NULL) |
| 86 | { |
| 87 | goto end; |
| 88 | } |
| 89 | cJSON_AddItemToArray(resolutions, resolution); |
| 90 | |
| 91 | width = cJSON_CreateNumber(resolution_numbers[index][0]); |
| 92 | if (width == NULL) |
| 93 | { |
| 94 | goto end; |
| 95 | } |
| 96 | cJSON_AddItemToObject(resolution, "width", width); |
| 97 | |
| 98 | height = cJSON_CreateNumber(resolution_numbers[index][1]); |
| 99 | if (height == NULL) |
| 100 | { |
| 101 | goto end; |
| 102 | } |
no test coverage detected
searching dependent graphs…