| 13 | DECLARE_SIMPLE(NetworkFunctions) |
| 14 | |
| 15 | TEST(NetworkFunctions, StringIPtoUint32) |
| 16 | { |
| 17 | unsigned int values[] = { 0, 1, 127, 254, 255 }; |
| 18 | const wxChar whitespace[] = { ' ', '\t', '\n' }; |
| 19 | int items = itemsof(values); |
| 20 | int whites = 2; |
| 21 | int zeros = 2; |
| 22 | |
| 23 | // Test a few standard IP combinations |
| 24 | for (int wl = 0; wl < whites; ++wl) { |
| 25 | for (int wr = 0; wr < whites; ++wr) { |
| 26 | for (int a = 0; a < items; ++a) { |
| 27 | for (int za = 0; za < zeros; ++za) { |
| 28 | for (int b = 0; b < items; ++b) { |
| 29 | for (int zb = 0; zb < zeros; ++zb) { |
| 30 | for (int c = 0; c < items; ++c) { |
| 31 | for (int zc = 0; zc < zeros; ++zc) { |
| 32 | for (int d = 0; d < items; ++d) { |
| 33 | for (int zd = 0; zd < zeros; ++zd) { |
| 34 | wxString IP; |
| 35 | |
| 36 | IP << wxString(' ', wl) |
| 37 | << wxString('0', za) |
| 38 | << values[a] |
| 39 | << '.' |
| 40 | << wxString('0', zb) |
| 41 | << values[b] |
| 42 | << '.' |
| 43 | << wxString('0', zc) |
| 44 | << values[c] |
| 45 | << '.' |
| 46 | << wxString('0', zd) |
| 47 | << values[d] |
| 48 | << wxString(' ', wr); |
| 49 | |
| 50 | uint32 resultIP = 17; |
| 51 | |
| 52 | ASSERT_TRUE(StringIPtoUint32(IP, resultIP)); |
| 53 | |
| 54 | uint32 expected = (values[d] << 24) | (values[c] << 16) | (values[b] << 8) | values[a]; |
| 55 | |
| 56 | ASSERT_EQUALS(expected, resultIP); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | |
| 69 | // Test invalid IPs |
| 70 | uint32 dummyIP = 27; |
| 71 | |
| 72 | // Missing fields |
nothing calls this directly
no test coverage detected