OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "dbus/values_util.h" | 5 #include "dbus/values_util.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/float_util.h" | 9 #include "base/float_util.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
442 ASSERT_TRUE(value.get() != NULL); | 442 ASSERT_TRUE(value.get() != NULL); |
443 EXPECT_TRUE(value->Equals(&kIntegerValue)); | 443 EXPECT_TRUE(value->Equals(&kIntegerValue)); |
444 value.reset(PopDataAsValue(&reader)); | 444 value.reset(PopDataAsValue(&reader)); |
445 ASSERT_TRUE(value.get() != NULL); | 445 ASSERT_TRUE(value.get() != NULL); |
446 EXPECT_TRUE(value->Equals(&kDoubleValue)); | 446 EXPECT_TRUE(value->Equals(&kDoubleValue)); |
447 value.reset(PopDataAsValue(&reader)); | 447 value.reset(PopDataAsValue(&reader)); |
448 ASSERT_TRUE(value.get() != NULL); | 448 ASSERT_TRUE(value.get() != NULL); |
449 EXPECT_TRUE(value->Equals(&kStringValue)); | 449 EXPECT_TRUE(value->Equals(&kStringValue)); |
450 } | 450 } |
451 | 451 |
452 TEST(ValuesUtilTest, AppendDictionary) { | |
keybuk
2014/04/03 16:32:23
You need test cases for the basic values too
armansito
2014/04/03 17:20:05
Done.
| |
453 // Set up the input dictionary. | |
454 const std::string kKey1 = "one"; | |
455 const std::string kKey2 = "two"; | |
456 const std::string kKey3 = "three"; | |
457 const std::string kKey4 = "four"; | |
458 const std::string kKey5 = "five"; | |
459 const std::string kKey6 = "six"; | |
460 | |
461 const bool kBoolValue = true; | |
462 const int32 kInt32Value = -45; | |
463 const double kDoubleValue = 4.9; | |
464 const std::string kStringValue = "fifty"; | |
465 | |
466 base::ListValue* list_value = new base::ListValue(); | |
467 list_value->AppendBoolean(kBoolValue); | |
468 list_value->AppendInteger(kInt32Value); | |
469 | |
470 base::DictionaryValue* dictionary_value = new base::DictionaryValue(); | |
471 dictionary_value->SetBoolean(kKey1, kBoolValue); | |
472 dictionary_value->SetInteger(kKey2, kDoubleValue); | |
473 | |
474 base::DictionaryValue test_dictionary; | |
475 test_dictionary.SetBoolean(kKey1, kBoolValue); | |
476 test_dictionary.SetInteger(kKey2, kInt32Value); | |
477 test_dictionary.SetDouble(kKey3, kDoubleValue); | |
478 test_dictionary.SetString(kKey4, kStringValue); | |
479 test_dictionary.Set(kKey5, list_value); // takes ownership | |
480 test_dictionary.Set(kKey6, dictionary_value); // takes ownership | |
481 | |
482 scoped_ptr<Response> response(Response::CreateEmpty()); | |
483 MessageWriter writer(response.get()); | |
484 AppendValueData(&writer, test_dictionary); | |
485 | |
486 // Read the data. | |
487 MessageReader reader(response.get()); | |
488 scoped_ptr<base::Value> value; | |
489 value.reset(PopDataAsValue(&reader)); | |
490 ASSERT_TRUE(value.get() != NULL); | |
491 EXPECT_TRUE(value->Equals(&test_dictionary)); | |
492 } | |
493 | |
494 TEST(ValuesUtilTest, AppendDictionaryAsVariant) { | |
495 // Set up the input dictionary. | |
496 const std::string kKey1 = "one"; | |
497 const std::string kKey2 = "two"; | |
498 const std::string kKey3 = "three"; | |
499 const std::string kKey4 = "four"; | |
500 const std::string kKey5 = "five"; | |
501 const std::string kKey6 = "six"; | |
502 | |
503 const bool kBoolValue = true; | |
504 const int32 kInt32Value = -45; | |
505 const double kDoubleValue = 4.9; | |
506 const std::string kStringValue = "fifty"; | |
507 | |
508 base::ListValue* list_value = new base::ListValue(); | |
509 list_value->AppendBoolean(kBoolValue); | |
510 list_value->AppendInteger(kInt32Value); | |
511 | |
512 base::DictionaryValue* dictionary_value = new base::DictionaryValue(); | |
513 dictionary_value->SetBoolean(kKey1, kBoolValue); | |
514 dictionary_value->SetInteger(kKey2, kDoubleValue); | |
515 | |
516 base::DictionaryValue test_dictionary; | |
517 test_dictionary.SetBoolean(kKey1, kBoolValue); | |
518 test_dictionary.SetInteger(kKey2, kInt32Value); | |
519 test_dictionary.SetDouble(kKey3, kDoubleValue); | |
520 test_dictionary.SetString(kKey4, kStringValue); | |
521 test_dictionary.Set(kKey5, list_value); // takes ownership | |
522 test_dictionary.Set(kKey6, dictionary_value); // takes ownership | |
523 | |
524 scoped_ptr<Response> response(Response::CreateEmpty()); | |
525 MessageWriter writer(response.get()); | |
526 AppendValueDataAsVariant(&writer, test_dictionary); | |
527 | |
528 // Read the data. | |
529 MessageReader reader(response.get()); | |
530 scoped_ptr<base::Value> value; | |
531 value.reset(PopDataAsValue(&reader)); | |
532 ASSERT_TRUE(value.get() != NULL); | |
533 EXPECT_TRUE(value->Equals(&test_dictionary)); | |
534 } | |
535 | |
536 TEST(ValuesUtilTest, AppendList) { | |
537 // Set up the input list. | |
538 const std::string kKey1 = "one"; | |
539 const std::string kKey2 = "two"; | |
540 | |
541 const bool kBoolValue = true; | |
542 const int32 kInt32Value = -45; | |
543 const double kDoubleValue = 4.9; | |
544 const std::string kStringValue = "fifty"; | |
545 | |
546 base::ListValue* list_value = new base::ListValue(); | |
547 list_value->AppendBoolean(kBoolValue); | |
548 list_value->AppendInteger(kInt32Value); | |
549 | |
550 base::DictionaryValue* dictionary_value = new base::DictionaryValue(); | |
551 dictionary_value->SetBoolean(kKey1, kBoolValue); | |
552 dictionary_value->SetInteger(kKey2, kDoubleValue); | |
553 | |
554 base::ListValue test_list; | |
555 test_list.AppendBoolean(kBoolValue); | |
556 test_list.AppendInteger(kInt32Value); | |
557 test_list.AppendDouble(kDoubleValue); | |
558 test_list.AppendString(kStringValue); | |
559 test_list.Append(list_value); // takes ownership | |
560 test_list.Append(dictionary_value); // takes ownership | |
561 | |
562 scoped_ptr<Response> response(Response::CreateEmpty()); | |
563 MessageWriter writer(response.get()); | |
564 AppendValueData(&writer, test_list); | |
565 | |
566 // Read the data. | |
567 MessageReader reader(response.get()); | |
568 scoped_ptr<base::Value> value; | |
569 value.reset(PopDataAsValue(&reader)); | |
570 ASSERT_TRUE(value.get() != NULL); | |
571 EXPECT_TRUE(value->Equals(&test_list)); | |
572 } | |
573 | |
574 TEST(ValuesUtilTest, AppendListAsVariant) { | |
575 // Set up the input list. | |
576 const std::string kKey1 = "one"; | |
577 const std::string kKey2 = "two"; | |
578 | |
579 const bool kBoolValue = true; | |
580 const int32 kInt32Value = -45; | |
581 const double kDoubleValue = 4.9; | |
582 const std::string kStringValue = "fifty"; | |
583 | |
584 base::ListValue* list_value = new base::ListValue(); | |
585 list_value->AppendBoolean(kBoolValue); | |
586 list_value->AppendInteger(kInt32Value); | |
587 | |
588 base::DictionaryValue* dictionary_value = new base::DictionaryValue(); | |
589 dictionary_value->SetBoolean(kKey1, kBoolValue); | |
590 dictionary_value->SetInteger(kKey2, kDoubleValue); | |
591 | |
592 base::ListValue test_list; | |
593 test_list.AppendBoolean(kBoolValue); | |
594 test_list.AppendInteger(kInt32Value); | |
595 test_list.AppendDouble(kDoubleValue); | |
596 test_list.AppendString(kStringValue); | |
597 test_list.Append(list_value); // takes ownership | |
598 test_list.Append(dictionary_value); // takes ownership | |
599 | |
600 scoped_ptr<Response> response(Response::CreateEmpty()); | |
601 MessageWriter writer(response.get()); | |
602 AppendValueDataAsVariant(&writer, test_list); | |
603 | |
604 // Read the data. | |
605 MessageReader reader(response.get()); | |
606 scoped_ptr<base::Value> value; | |
607 value.reset(PopDataAsValue(&reader)); | |
608 ASSERT_TRUE(value.get() != NULL); | |
609 EXPECT_TRUE(value->Equals(&test_list)); | |
610 } | |
611 | |
452 } // namespace dbus | 612 } // namespace dbus |
OLD | NEW |