TYPED_TEST(DocumentMove, MoveAssignment) { typedef TypeParam Allocator; typedef GenericDocument<UTF8<>, Allocator> Document; Allocator allocator; Document a(&allocator); a.Parse("[\"one\", \"two\", \"three\"]"); EXPECT_FALSE(a.HasParseError()); EXPECT_TRUE(a.IsArray()); EXPECT_EQ(3u, a.Size()); EXPECT_EQ(&a.GetAllocator(), &allocator); // Document b; b = a; // does not compile (!is_copy_assignable) Document b; b = std::move(a); EXPECT_TRUE(a.IsNull()); EXPECT_TRUE(b.IsArray()); EXPECT_EQ(3u, b.Size()); EXPECT_EQ(&a.GetAllocator(), (void*)0); EXPECT_EQ(&b.GetAllocator(), &allocator); b.Parse("{\"Foo\": \"Bar\", \"Baz\": 42}"); EXPECT_FALSE(b.HasParseError()); EXPECT_TRUE(b.IsObject()); EXPECT_EQ(2u, b.MemberCount()); // Document c; c = a; // does not compile (see static_assert) Document c; c = std::move(b); EXPECT_TRUE(b.IsNull()); EXPECT_TRUE(c.IsObject()); EXPECT_EQ(2u, c.MemberCount()); EXPECT_EQ(&b.GetAllocator(), (void*)0); EXPECT_EQ(&c.GetAllocator(), &allocator); }
//将支持api保存到mSupportedApiSet void Device::loadSupportedApiList(const Document &replyJson) { mSupportedApiSet.clear(); if (replyJson == NULL || replyJson.IsNull()) return; if (replyJson.HasMember("error")) { return; } Value::ConstArray a = replyJson["result"].GetArray()[0].GetArray(); for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr) { mSupportedApiSet.insert(itr->GetString()); } }
TEST(SchemaValidatingReader, Invalid) { Document sd; sd.Parse("{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}"); SchemaDocument s(sd); Document d; StringStream ss("\"ABCD\""); SchemaValidatingReader<kParseDefaultFlags, StringStream, UTF8<> > reader(ss, s); d.Populate(reader); EXPECT_FALSE(reader.GetParseResult()); EXPECT_FALSE(reader.IsValid()); EXPECT_EQ(kParseErrorTermination, reader.GetParseResult().Code()); EXPECT_STREQ("maxLength", reader.GetInvalidSchemaKeyword()); EXPECT_TRUE(reader.GetInvalidSchemaPointer() == SchemaDocument::PointerType("")); EXPECT_TRUE(reader.GetInvalidDocumentPointer() == SchemaDocument::PointerType("")); EXPECT_TRUE(d.IsNull()); }
//获取jpg数据 DWORD WINAPI retrieveJPG(LPVOID param) { CLiveview *dlg = (CLiveview *)param; Document replyJson; replyJson = dlg->indevice->startLiveview(); if (replyJson.IsNull()) { //通讯失败 dlg->fetching = false; dlg->FreshUI(); return -1; } if (replyJson.HasMember("error")) { //相机故障 dlg->fetching = false; dlg->FreshUI(); return -1; } CString liveviewUrl = replyJson["result"].GetArray()[0].GetString(); LiveviewSlicer slicer; if (!slicer.open(liveviewUrl)) { //读取数据失败 dlg->fetching = false; dlg->FreshUI(); return -1; } dlg->fetching = true; while (dlg->fetching) { Payload payload = slicer.nextPayload(); LONG size = payload.jpegDataSize; if (size <= 0) { slicer.close(); break; } HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, size); PUCHAR pData = (PUCHAR)GlobalLock(hGlobal); int readLen = 0; while (readLen < size) { readLen += slicer.file->Read(pData + readLen, size - readLen); } GlobalUnlock(hGlobal); payload.paddingData = new UCHAR[payload.paddingDataSize]; readLen = 0; while (readLen < payload.paddingDataSize) { readLen += slicer.file->Read(payload.paddingData + readLen, payload.paddingDataSize - readLen); } delete[] payload.paddingData; while (dlg->mJpegQueue.size() >= 5) { GlobalFree(dlg->mJpegQueue.front()); dlg->mJpegQueue.pop(); } dlg->mJpegQueue.push(hGlobal); } //退出了 while (!dlg->mJpegQueue.empty()) { dlg->mJpegQueue.pop(); } dlg->fetching = false; dlg->FreshUI(); return -1; }