| 82 | } while (0) |
| 83 | |
| 84 | int |
| 85 | main(int argc, char *argv[]) |
| 86 | { |
| 87 | plan_tests(131); |
| 88 | |
| 89 | is_size_t(base64_encoded_length(0),(size_t)0); |
| 90 | is_size_t(base64_encoded_length(1),(size_t)4); |
| 91 | is_size_t(base64_encoded_length(2),(size_t)4); |
| 92 | is_size_t(base64_encoded_length(3),(size_t)4); |
| 93 | is_size_t(base64_encoded_length(512),(size_t)684); |
| 94 | |
| 95 | /* straight from page 11 of http://tools.ietf.org/html/rfc4648 */ |
| 96 | test_encode("",0,""); |
| 97 | test_encode("f",1,"Zg=="); |
| 98 | test_encode("fo",2,"Zm8="); |
| 99 | |
| 100 | test_encode("foo",3,"Zm9v"); |
| 101 | test_encode("foob",4,"Zm9vYg=="); |
| 102 | test_encode("fooba",5,"Zm9vYmE="); |
| 103 | test_encode("foobar",6,"Zm9vYmFy"); |
| 104 | |
| 105 | /* a few more */ |
| 106 | test_encode("foobarb",7,"Zm9vYmFyYg=="); |
| 107 | test_encode("foobarba",8,"Zm9vYmFyYmE="); |
| 108 | test_encode("foobarbaz",9,"Zm9vYmFyYmF6"); |
| 109 | |
| 110 | test_encode("foobart",7,"Zm9vYmFydA=="); |
| 111 | |
| 112 | test_encode("abcdefghijklmnopqrstuvwxyz",26,"YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo="); |
| 113 | test_encode("\x05\x05\x01\x00\x07",5,"BQUBAAc="); |
| 114 | |
| 115 | test_encode("FOO",3,"Rk9P"); |
| 116 | test_encode("Z",1,"Wg=="); |
| 117 | |
| 118 | /* decode testing */ |
| 119 | |
| 120 | test_decode("",0,"",0); |
| 121 | test_decode("Zg==",4,"f",1); |
| 122 | test_decode("Zm8=",4,"fo",2); |
| 123 | test_decode("Zm9v",4,"foo",3); |
| 124 | test_decode("Zm9vYg==",8,"foob",4); |
| 125 | test_decode("Zm9vYmE=",8,"fooba",5); |
| 126 | test_decode("Zm9vYmFy",8,"foobar",6); |
| 127 | test_decode("Zm9vYmFyYg==",12,"foobarb",7); |
| 128 | test_decode("Zm9vYmFyYmE=",12,"foobarba",8); |
| 129 | test_decode("Zm9vYmFyYmF6",12,"foobarbaz",9); |
| 130 | |
| 131 | test_decode("Rk9P",4,"FOO",3); |
| 132 | |
| 133 | test_decode("Wg==",4,"Z",1); |
| 134 | test_decode("AA==",4,"\0",1); |
| 135 | test_decode("AAA=",4,"\0\0",2); |
| 136 | |
| 137 | { |
| 138 | const char *binary = "\x01\x00\x03"; |
| 139 | const size_t binarylen = 3; |
| 140 | |
| 141 | char * decoded; |
nothing calls this directly
no test coverage detected