| 9 | static const char *TOOL_NAME = "map_test"; |
| 10 | |
| 11 | static int TestMap(const char *pMap, bool CalcHashes, IStorage *pStorage) |
| 12 | { |
| 13 | log_info(TOOL_NAME, "Testing map '%s'...", pMap); |
| 14 | |
| 15 | CDataFileReader Reader; |
| 16 | if(!Reader.Open(pStorage, pMap, IStorage::TYPE_ABSOLUTE)) |
| 17 | { |
| 18 | log_error(TOOL_NAME, "Failed to open map '%s' for reading", pMap); |
| 19 | return -1; |
| 20 | } |
| 21 | |
| 22 | char aSha256Str[SHA256_MAXSTRSIZE]; |
| 23 | sha256_str(Reader.Sha256(), aSha256Str, sizeof(aSha256Str)); |
| 24 | log_info(TOOL_NAME, "File size: %d", Reader.Size()); |
| 25 | log_info(TOOL_NAME, "File SHA256: %s", aSha256Str); |
| 26 | log_info(TOOL_NAME, "File CRC32: %08x", Reader.Crc()); |
| 27 | log_info(TOOL_NAME, "Num items: %d", Reader.NumItems()); |
| 28 | log_info(TOOL_NAME, "Num data: %d", Reader.NumData()); |
| 29 | |
| 30 | for(int Index = 0; Index < Reader.NumItems(); Index++) |
| 31 | { |
| 32 | log_info(TOOL_NAME, "Item %d:", Index); |
| 33 | |
| 34 | int Type, Id; |
| 35 | CUuid Uuid; |
| 36 | const void *pItem = Reader.GetItem(Index, &Type, &Id, &Uuid); |
| 37 | |
| 38 | log_info(TOOL_NAME, " Type: %d", Type); |
| 39 | log_info(TOOL_NAME, " ID: %d", Id); |
| 40 | char aUuidStr[UUID_MAXSTRSIZE]; |
| 41 | FormatUuid(Uuid, aUuidStr, sizeof(aUuidStr)); |
| 42 | log_info(TOOL_NAME, " UUID: %s", aUuidStr); |
| 43 | |
| 44 | const int Size = Reader.GetItemSize(Index); |
| 45 | log_info(TOOL_NAME, " Size: %d bytes", Size); |
| 46 | |
| 47 | if(CalcHashes) |
| 48 | { |
| 49 | const SHA256_DIGEST ItemDataSha256 = sha256(pItem, Size); |
| 50 | sha256_str(ItemDataSha256, aSha256Str, sizeof(aSha256Str)); |
| 51 | log_info(TOOL_NAME, " Data (SHA256): %s", aSha256Str); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | for(int Index = 0; Index < Reader.NumData(); Index++) |
| 56 | { |
| 57 | log_info(TOOL_NAME, "Data %d:", Index); |
| 58 | |
| 59 | const int Size = Reader.GetDataSize(Index); |
| 60 | log_info(TOOL_NAME, " Size: %d bytes", Size); |
| 61 | |
| 62 | const void *pData = Reader.GetData(Index); |
| 63 | if(pData == nullptr) |
| 64 | { |
| 65 | log_info(TOOL_NAME, " Data erroneous"); |
| 66 | } |
| 67 | else if(CalcHashes) |
| 68 | { |
no test coverage detected