| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 package rawdatastore | 5 package rawdatastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "bytes" | 8 "bytes" |
| 9 "io" | 9 "io" |
| 10 "testing" | 10 "testing" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 }, | 74 }, |
| 75 }, | 75 }, |
| 76 } | 76 } |
| 77 | 77 |
| 78 Convey("PropertyMap serialization", t, func() { | 78 Convey("PropertyMap serialization", t, func() { |
| 79 Convey("round trip", func() { | 79 Convey("round trip", func() { |
| 80 for _, tc := range tests { | 80 for _, tc := range tests { |
| 81 tc := tc | 81 tc := tc |
| 82 Convey(tc.name, func() { | 82 Convey(tc.name, func() { |
| 83 buf := &bytes.Buffer{} | 83 buf := &bytes.Buffer{} |
| 84 » » » » » WritePropertyMap(buf, tc.props, WithCont
ext) | 84 » » » » » tc.props.Write(buf, WithContext) |
| 85 » » » » » dec, err := ReadPropertyMap(buf, WithCon
text, "", "") | 85 » » » » » dec := PropertyMap{} |
| 86 » » » » » err := dec.Read(buf, WithContext, "", ""
) |
| 86 So(err, ShouldBeNil) | 87 So(err, ShouldBeNil) |
| 87 So(dec, ShouldResemble, tc.props) | 88 So(dec, ShouldResemble, tc.props) |
| 88 }) | 89 }) |
| 89 } | 90 } |
| 90 }) | 91 }) |
| 91 }) | 92 }) |
| 92 } | 93 } |
| 93 | 94 |
| 94 func TestSerializationReadMisc(t *testing.T) { | 95 func TestSerializationReadMisc(t *testing.T) { |
| 95 t.Parallel() | 96 t.Parallel() |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 cmpbin.WriteString(buf, "hi") | 222 cmpbin.WriteString(buf, "hi") |
| 222 buf.WriteByte(byte(PTInt)) | 223 buf.WriteByte(byte(PTInt)) |
| 223 cmpbin.WriteInt(buf, -2) | 224 cmpbin.WriteInt(buf, -2) |
| 224 _, err := ReadKey(buf, WithContext, "",
"") | 225 _, err := ReadKey(buf, WithContext, "",
"") |
| 225 So(err, ShouldErrLike, "zero/negative") | 226 So(err, ShouldErrLike, "zero/negative") |
| 226 }) | 227 }) |
| 227 }) | 228 }) |
| 228 }) | 229 }) |
| 229 | 230 |
| 230 Convey("ReadGeoPoint", func() { | 231 Convey("ReadGeoPoint", func() { |
| 232 gp := GeoPoint{} |
| 231 Convey("trunc 1", func() { | 233 Convey("trunc 1", func() { |
| 232 » » » » _, err := ReadGeoPoint(buf) | 234 » » » » err := gp.Read(buf) |
| 233 So(err, ShouldEqual, io.EOF) | 235 So(err, ShouldEqual, io.EOF) |
| 234 }) | 236 }) |
| 235 Convey("trunc 2", func() { | 237 Convey("trunc 2", func() { |
| 236 cmpbin.WriteFloat64(buf, 100) | 238 cmpbin.WriteFloat64(buf, 100) |
| 237 » » » » _, err := ReadGeoPoint(buf) | 239 » » » » err := gp.Read(buf) |
| 238 So(err, ShouldEqual, io.EOF) | 240 So(err, ShouldEqual, io.EOF) |
| 239 }) | 241 }) |
| 240 Convey("invalid", func() { | 242 Convey("invalid", func() { |
| 241 cmpbin.WriteFloat64(buf, 100) | 243 cmpbin.WriteFloat64(buf, 100) |
| 242 cmpbin.WriteFloat64(buf, 1000) | 244 cmpbin.WriteFloat64(buf, 1000) |
| 243 » » » » _, err := ReadGeoPoint(buf) | 245 » » » » err := gp.Read(buf) |
| 244 So(err, ShouldErrLike, "invalid GeoPoint") | 246 So(err, ShouldErrLike, "invalid GeoPoint") |
| 245 }) | 247 }) |
| 246 }) | 248 }) |
| 247 | 249 |
| 248 Convey("WriteTime", func() { | 250 Convey("WriteTime", func() { |
| 249 Convey("in non-UTC!", func() { | 251 Convey("in non-UTC!", func() { |
| 250 pst, err := time.LoadLocation("America/Los_Angel
es") | 252 pst, err := time.LoadLocation("America/Los_Angel
es") |
| 251 So(err, ShouldBeNil) | 253 So(err, ShouldBeNil) |
| 252 So(func() { | 254 So(func() { |
| 253 WriteTime(buf, time.Now().In(pst)) | 255 WriteTime(buf, time.Now().In(pst)) |
| 254 }, ShouldPanic) | 256 }, ShouldPanic) |
| 255 }) | 257 }) |
| 256 }) | 258 }) |
| 257 | 259 |
| 258 Convey("ReadTime", func() { | 260 Convey("ReadTime", func() { |
| 259 Convey("trunc 1", func() { | 261 Convey("trunc 1", func() { |
| 260 _, err := ReadTime(buf) | 262 _, err := ReadTime(buf) |
| 261 So(err, ShouldEqual, io.EOF) | 263 So(err, ShouldEqual, io.EOF) |
| 262 }) | 264 }) |
| 263 }) | 265 }) |
| 264 | 266 |
| 265 Convey("ReadProperty", func() { | 267 Convey("ReadProperty", func() { |
| 268 p := Property{} |
| 266 Convey("trunc 1", func() { | 269 Convey("trunc 1", func() { |
| 267 » » » » _, err := ReadProperty(buf, WithContext, "", "") | 270 » » » » err := p.Read(buf, WithContext, "", "") |
| 268 So(err, ShouldEqual, io.EOF) | 271 So(err, ShouldEqual, io.EOF) |
| 272 So(p.Type(), ShouldEqual, PTNull) |
| 273 So(p.Value(), ShouldBeNil) |
| 269 }) | 274 }) |
| 270 Convey("trunc (PTBytes)", func() { | 275 Convey("trunc (PTBytes)", func() { |
| 271 buf.WriteByte(byte(PTBytes)) | 276 buf.WriteByte(byte(PTBytes)) |
| 272 » » » » _, err := ReadProperty(buf, WithContext, "", "") | 277 » » » » err := p.Read(buf, WithContext, "", "") |
| 273 So(err, ShouldEqual, io.EOF) | 278 So(err, ShouldEqual, io.EOF) |
| 274 }) | 279 }) |
| 275 Convey("trunc (PTBlobKey)", func() { | 280 Convey("trunc (PTBlobKey)", func() { |
| 276 buf.WriteByte(byte(PTBlobKey)) | 281 buf.WriteByte(byte(PTBlobKey)) |
| 277 » » » » _, err := ReadProperty(buf, WithContext, "", "") | 282 » » » » err := p.Read(buf, WithContext, "", "") |
| 278 So(err, ShouldEqual, io.EOF) | 283 So(err, ShouldEqual, io.EOF) |
| 279 }) | 284 }) |
| 280 Convey("invalid type", func() { | 285 Convey("invalid type", func() { |
| 281 buf.WriteByte(byte(PTUnknown + 1)) | 286 buf.WriteByte(byte(PTUnknown + 1)) |
| 282 » » » » _, err := ReadProperty(buf, WithContext, "", "") | 287 » » » » err := p.Read(buf, WithContext, "", "") |
| 283 So(err, ShouldErrLike, "unknown type!") | 288 So(err, ShouldErrLike, "unknown type!") |
| 284 }) | 289 }) |
| 285 }) | 290 }) |
| 286 | 291 |
| 287 Convey("ReadPropertyMap", func() { | 292 Convey("ReadPropertyMap", func() { |
| 293 pm := PropertyMap{} |
| 288 Convey("trunc 1", func() { | 294 Convey("trunc 1", func() { |
| 289 » » » » _, err := ReadPropertyMap(buf, WithContext, "",
"") | 295 » » » » err := pm.Read(buf, WithContext, "", "") |
| 290 So(err, ShouldEqual, io.EOF) | 296 So(err, ShouldEqual, io.EOF) |
| 291 }) | 297 }) |
| 292 Convey("too many rows", func() { | 298 Convey("too many rows", func() { |
| 293 cmpbin.WriteUint(buf, 1000000) | 299 cmpbin.WriteUint(buf, 1000000) |
| 294 » » » » _, err := ReadPropertyMap(buf, WithContext, "",
"") | 300 » » » » err := pm.Read(buf, WithContext, "", "") |
| 295 So(err, ShouldErrLike, "huge number of rows") | 301 So(err, ShouldErrLike, "huge number of rows") |
| 296 }) | 302 }) |
| 297 Convey("trunc 2", func() { | 303 Convey("trunc 2", func() { |
| 298 cmpbin.WriteUint(buf, 10) | 304 cmpbin.WriteUint(buf, 10) |
| 299 » » » » _, err := ReadPropertyMap(buf, WithContext, "",
"") | 305 » » » » err := pm.Read(buf, WithContext, "", "") |
| 300 So(err, ShouldEqual, io.EOF) | 306 So(err, ShouldEqual, io.EOF) |
| 301 }) | 307 }) |
| 302 Convey("trunc 3", func() { | 308 Convey("trunc 3", func() { |
| 303 cmpbin.WriteUint(buf, 10) | 309 cmpbin.WriteUint(buf, 10) |
| 304 cmpbin.WriteString(buf, "ohai") | 310 cmpbin.WriteString(buf, "ohai") |
| 305 » » » » _, err := ReadPropertyMap(buf, WithContext, "",
"") | 311 » » » » err := pm.Read(buf, WithContext, "", "") |
| 306 So(err, ShouldEqual, io.EOF) | 312 So(err, ShouldEqual, io.EOF) |
| 307 }) | 313 }) |
| 308 Convey("too many values", func() { | 314 Convey("too many values", func() { |
| 309 cmpbin.WriteUint(buf, 10) | 315 cmpbin.WriteUint(buf, 10) |
| 310 cmpbin.WriteString(buf, "ohai") | 316 cmpbin.WriteString(buf, "ohai") |
| 311 cmpbin.WriteUint(buf, 100000) | 317 cmpbin.WriteUint(buf, 100000) |
| 312 » » » » _, err := ReadPropertyMap(buf, WithContext, "",
"") | 318 » » » » err := pm.Read(buf, WithContext, "", "") |
| 313 So(err, ShouldErrLike, "huge number of propertie
s") | 319 So(err, ShouldErrLike, "huge number of propertie
s") |
| 314 }) | 320 }) |
| 315 Convey("trunc 4", func() { | 321 Convey("trunc 4", func() { |
| 316 cmpbin.WriteUint(buf, 10) | 322 cmpbin.WriteUint(buf, 10) |
| 317 cmpbin.WriteString(buf, "ohai") | 323 cmpbin.WriteString(buf, "ohai") |
| 318 cmpbin.WriteUint(buf, 10) | 324 cmpbin.WriteUint(buf, 10) |
| 319 » » » » _, err := ReadPropertyMap(buf, WithContext, "",
"") | 325 » » » » err := pm.Read(buf, WithContext, "", "") |
| 320 So(err, ShouldEqual, io.EOF) | 326 So(err, ShouldEqual, io.EOF) |
| 321 }) | 327 }) |
| 322 }) | 328 }) |
| 323 }) | 329 }) |
| 324 } | 330 } |
| OLD | NEW |