(t *testing.T)
| 573 | } |
| 574 | |
| 575 | func TestWriteJSONProtocolMap(t *testing.T) { |
| 576 | thetype := "map" |
| 577 | trans := NewTMemoryBuffer() |
| 578 | p := NewTJSONProtocol(trans) |
| 579 | p.WriteMapBegin(context.Background(), TType(I32), TType(DOUBLE), len(DOUBLE_VALUES)) |
| 580 | for k, value := range DOUBLE_VALUES { |
| 581 | if e := p.WriteI32(context.Background(), int32(k)); e != nil { |
| 582 | t.Fatalf("Unable to write %s key int32 value %v due to error: %s", thetype, k, e.Error()) |
| 583 | } |
| 584 | if e := p.WriteDouble(context.Background(), value); e != nil { |
| 585 | t.Fatalf("Unable to write %s value float64 value %v due to error: %s", thetype, value, e.Error()) |
| 586 | } |
| 587 | } |
| 588 | p.WriteMapEnd(context.Background()) |
| 589 | if e := p.Flush(context.Background()); e != nil { |
| 590 | t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error()) |
| 591 | } |
| 592 | str := trans.String() |
| 593 | if str[0] != '[' || str[len(str)-1] != ']' { |
| 594 | t.Fatalf("Bad value for %s, wrote: %v, in go: %v", thetype, str, DOUBLE_VALUES) |
| 595 | } |
| 596 | expectedKeyType, expectedValueType, expectedSize, err := p.ReadMapBegin(context.Background()) |
| 597 | if err != nil { |
| 598 | t.Fatalf("Error while reading map begin: %s", err.Error()) |
| 599 | } |
| 600 | if expectedKeyType != I32 { |
| 601 | t.Fatal("Expected map key type ", I32, ", but was ", expectedKeyType) |
| 602 | } |
| 603 | if expectedValueType != DOUBLE { |
| 604 | t.Fatal("Expected map value type ", DOUBLE, ", but was ", expectedValueType) |
| 605 | } |
| 606 | if expectedSize != len(DOUBLE_VALUES) { |
| 607 | t.Fatal("Expected map size of ", len(DOUBLE_VALUES), ", but was ", expectedSize) |
| 608 | } |
| 609 | for k, value := range DOUBLE_VALUES { |
| 610 | ik, err := p.ReadI32(context.Background()) |
| 611 | if err != nil { |
| 612 | t.Fatalf("Bad key for %s index %v, wrote: %v, expected: %v, error: %s", thetype, k, ik, k, err.Error()) |
| 613 | } |
| 614 | if int(ik) != k { |
| 615 | t.Fatalf("Bad key for %s index %v, wrote: %v, expected: %v", thetype, k, ik, k) |
| 616 | } |
| 617 | dv, err := p.ReadDouble(context.Background()) |
| 618 | if err != nil { |
| 619 | t.Fatalf("Bad value for %s index %v, wrote: %v, expected: %v, error: %s", thetype, k, dv, value, err.Error()) |
| 620 | } |
| 621 | s := strconv.FormatFloat(dv, 'g', 10, 64) |
| 622 | if math.IsInf(value, 1) { |
| 623 | if !math.IsInf(dv, 1) { |
| 624 | t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_INFINITY)) |
| 625 | } |
| 626 | } else if math.IsInf(value, 0) { |
| 627 | if !math.IsInf(dv, 0) { |
| 628 | t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_NEGATIVE_INFINITY)) |
| 629 | } |
| 630 | } else if math.IsNaN(value) { |
| 631 | if !math.IsNaN(dv) { |
| 632 | t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_NAN)) |
nothing calls this directly
no test coverage detected