Karl Schultz | b932f10 | 2016-02-04 09:41:29 -0700 | [diff] [blame] | 1 | /////////////////////////////////////////////////////////////////////////////// |
Antoine Labour | e3795c1 | 2015-10-27 12:21:09 -0700 | [diff] [blame] | 2 | // |
Karl Schultz | b932f10 | 2016-02-04 09:41:29 -0700 | [diff] [blame] | 3 | // Copyright (c) 2015-2016 The Khronos Group Inc. |
| 4 | // Copyright (c) 2015-2016 Valve Corporation |
| 5 | // Copyright (c) 2015-2016 LunarG, Inc. |
| 6 | // Copyright (c) 2015-2016 Google, Inc. |
Antoine Labour | e3795c1 | 2015-10-27 12:21:09 -0700 | [diff] [blame] | 7 | // |
Karl Schultz | b932f10 | 2016-02-04 09:41:29 -0700 | [diff] [blame] | 8 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
| 9 | // of this software and/or associated documentation files (the "Materials"), to |
| 10 | // deal in the Materials without restriction, including without limitation the |
| 11 | // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 12 | // sell copies of the Materials, and to permit persons to whom the Materials are |
| 13 | // furnished to do so, subject to the following conditions: |
Antoine Labour | e3795c1 | 2015-10-27 12:21:09 -0700 | [diff] [blame] | 14 | // |
Karl Schultz | b932f10 | 2016-02-04 09:41:29 -0700 | [diff] [blame] | 15 | // The above copyright notice(s) and this permission notice shall be included in |
| 16 | // all copies or substantial portions of the Materials. |
| 17 | // |
Karl Schultz | b932f10 | 2016-02-04 09:41:29 -0700 | [diff] [blame] | 18 | // THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
Antoine Labour | 38841df | 2016-01-28 15:05:57 -0800 | [diff] [blame] | 19 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
Karl Schultz | b932f10 | 2016-02-04 09:41:29 -0700 | [diff] [blame] | 20 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 21 | // |
| 22 | // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| 23 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 24 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE |
| 25 | // USE OR OTHER DEALINGS IN THE MATERIALS. |
| 26 | /////////////////////////////////////////////////////////////////////////////// |
Antoine Labour | e3795c1 | 2015-10-27 12:21:09 -0700 | [diff] [blame] | 27 | |
| 28 | #include "vkjson.h" |
| 29 | |
| 30 | #include <stdlib.h> |
| 31 | #include <string.h> |
| 32 | |
| 33 | #include <iostream> |
| 34 | |
| 35 | #define EXPECT(X) if (!(X)) \ |
| 36 | ReportFailure(__FILE__, __LINE__, #X); |
| 37 | |
| 38 | #define ASSERT(X) if (!(X)) { \ |
| 39 | ReportFailure(__FILE__, __LINE__, #X); \ |
| 40 | return 2; \ |
| 41 | } |
| 42 | |
| 43 | int g_failures; |
| 44 | |
| 45 | void ReportFailure(const char* file, int line, const char* assertion) { |
| 46 | std::cout << file << ":" << line << ": \"" << assertion << "\" failed." |
| 47 | << std::endl; |
| 48 | ++g_failures; |
| 49 | } |
| 50 | |
| 51 | int main(int argc, char* argv[]) { |
| 52 | std::string errors; |
| 53 | bool result = false; |
| 54 | |
| 55 | const char name[] = "Test device"; |
| 56 | VkJsonAllProperties device_props; |
| 57 | memcpy(device_props.properties.deviceName, name, sizeof(name)); |
| 58 | device_props.properties.limits.maxImageDimension1D = 3; |
| 59 | device_props.properties.limits.maxSamplerLodBias = 3.5f; |
| 60 | device_props.properties.limits.bufferImageGranularity = 0x1ffffffffull; |
| 61 | device_props.properties.limits.maxViewportDimensions[0] = 1; |
| 62 | device_props.properties.limits.maxViewportDimensions[1] = 2; |
| 63 | VkFormatProperties format_props = { |
| 64 | VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT, |
| 65 | VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT, |
| 66 | VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT}; |
| 67 | device_props.formats.insert( |
| 68 | std::make_pair(VK_FORMAT_R8_UNORM, format_props)); |
| 69 | device_props.formats.insert( |
| 70 | std::make_pair(VK_FORMAT_R8G8_UNORM, format_props)); |
| 71 | std::string json = VkJsonAllPropertiesToJson(device_props); |
| 72 | std::cout << json << std::endl; |
| 73 | |
| 74 | VkJsonAllProperties device_props2; |
| 75 | result = VkJsonAllPropertiesFromJson(json, &device_props2, &errors); |
| 76 | EXPECT(result); |
| 77 | if (!result) |
| 78 | std::cout << "Error: " << errors << std::endl; |
| 79 | |
| 80 | EXPECT(!memcmp(&device_props.properties, |
| 81 | &device_props2.properties, |
| 82 | sizeof(device_props.properties))); |
| 83 | for (auto& kv : device_props.formats) { |
| 84 | auto it = device_props2.formats.find(kv.first); |
| 85 | EXPECT(it != device_props2.formats.end()); |
| 86 | EXPECT(!memcmp(&kv.second, &it->second, sizeof(kv.second))); |
| 87 | } |
| 88 | |
| 89 | VkImageFormatProperties props = {0}; |
| 90 | json = VkJsonImageFormatPropertiesToJson(props); |
Antoine Labour | e3795c1 | 2015-10-27 12:21:09 -0700 | [diff] [blame] | 91 | VkImageFormatProperties props2 = {0}; |
| 92 | result = VkJsonImageFormatPropertiesFromJson(json, &props2, &errors); |
| 93 | EXPECT(result); |
| 94 | if (!result) |
| 95 | std::cout << "Error: " << errors << std::endl; |
| 96 | |
| 97 | EXPECT(!memcmp(&props, &props2, sizeof(props))); |
| 98 | |
| 99 | if (g_failures) { |
| 100 | std::cout << g_failures << " failures." << std::endl; |
| 101 | return 1; |
| 102 | } else { |
| 103 | std::cout << "Success." << std::endl; |
| 104 | return 0; |
| 105 | } |
| 106 | } |