|
8 | 8 | #include <json/json.h>
|
9 | 9 | #include <cstring>
|
10 | 10 | #include <limits>
|
| 11 | +#include <sstream> |
| 12 | +#include <string> |
| 13 | +#include <iostream> |
| 14 | +#include <iomanip> |
11 | 15 |
|
12 | 16 | // Make numeric limits more convenient to talk about.
|
13 | 17 | // Assumes int type in 32 bits.
|
@@ -2430,6 +2434,31 @@ JSONTEST_FIXTURE(IteratorTest, indexes) {
|
2430 | 2434 | JSONTEST_ASSERT(it == json.end());
|
2431 | 2435 | }
|
2432 | 2436 |
|
| 2437 | +JSONTEST_FIXTURE(IteratorTest, const) { |
| 2438 | + Json::Value const v; |
| 2439 | + Json::Value::iterator it = v.begin(); // This *should not* compile, but does. |
| 2440 | + |
| 2441 | + Json::Value value; |
| 2442 | + |
| 2443 | + for(int i = 9; i < 12; ++i) |
| 2444 | + { |
| 2445 | + std::ostringstream out; |
| 2446 | + out << std::setw(2) << i; |
| 2447 | + std::string str = out.str(); |
| 2448 | + value[str] = str; |
| 2449 | + } |
| 2450 | + |
| 2451 | + std::ostringstream out; |
| 2452 | + //in old code, this will get a compile error |
| 2453 | + Json::Value::const_iterator iter = value.begin(); |
| 2454 | + for(; iter != value.end(); ++iter) |
| 2455 | + { |
| 2456 | + out << *iter << ','; |
| 2457 | + } |
| 2458 | + std::string expected = "\" 9\",\"10\",\"11\","; |
| 2459 | + JSONTEST_ASSERT_STRING_EQUAL(expected, out.str()); |
| 2460 | +} |
| 2461 | + |
2433 | 2462 | int main(int argc, const char* argv[]) {
|
2434 | 2463 | JsonTest::Runner runner;
|
2435 | 2464 | JSONTEST_REGISTER_FIXTURE(runner, ValueTest, checkNormalizeFloatingPointStr);
|
@@ -2500,6 +2529,7 @@ int main(int argc, const char* argv[]) {
|
2500 | 2529 | JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, distance);
|
2501 | 2530 | JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, names);
|
2502 | 2531 | JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, indexes);
|
| 2532 | + JSONTEST_REGISTER_FIXTURE(runner, IteratorTest, const); |
2503 | 2533 |
|
2504 | 2534 | return runner.runCommandLine(argc, argv);
|
2505 | 2535 | }
|
0 commit comments