void GeneratorTest() { char* string; JsonObject* root = CreateJsonObject(); JsonObject* element = CreateJsonObject(); JsonArray* array = CreateJsonArray(); AddInteger(array, 0); AddReal(array, 0.0); AddBoolean(array, FALSE); AddObject(array, element); AddString(array, "element"); AddNull(array); PutNull(root, "0"); PutInteger(root, "Year", 1970); PutInteger(root, "Month", 3); PutInteger(root, "Date", 18); PutArray(root, "Array", array); PutBoolean(root, "Proposition", TRUE); PutString(root, "Text", "Hello World"); PutReal(root, "Pi", 3.14159265358979323846264338327950288419716939937510582097494459230781640); string = ToString(root); printf("%s", string); printf("\r\n"); EXPECT_EQUAL_STRING("{\"0\":null,\"Year\":1970,\"Month\":3,\"Date\":18,\"Array\":[0,0.000000,false,{},\"element\",null],\"Proposition\":true,\"Text\":\"Hello World\",\"Pi\":3.141593}", string); free(string); ClearJsonObject(root); ClearJsonArray(array); string = ToString(root); EXPECT_EQUAL_STRING("{}", string); free(string); }
void DiagrammarInterface::LaunchWorld() { glSetCurrentContextPPAPI(context_.pp_resource()); world_.Read(CreateJsonObject("/http/path_simple.json")); world_.Start(); drawer_ = new NaClDrawer(world_); SimulationLoop(); }
VOID VirusTotalBuildJsonArray( _In_ PVIRUSTOTAL_FILE_HASH_ENTRY Entry, _In_ PVOID JsonArray ) { HANDLE fileHandle; FILE_NETWORK_OPEN_INFORMATION fileAttributeInfo; PPH_STRING hashString = NULL; if (NT_SUCCESS(PhQueryFullAttributesFileWin32( Entry->FileName->Buffer, &fileAttributeInfo ))) { Entry->CreationTime = VirusTotalTimeString(&fileAttributeInfo.CreationTime); } if (NT_SUCCESS(PhCreateFileWin32( &fileHandle, Entry->FileName->Buffer, FILE_GENERIC_READ, 0, FILE_SHARE_READ, FILE_OPEN, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT // FILE_OPEN_FOR_BACKUP_INTENT ))) { if (NT_SUCCESS(HashFileAndResetPosition( fileHandle, &fileAttributeInfo.EndOfFile, Sha256HashAlgorithm, &hashString ))) { PVOID entry; Entry->FileHash = hashString; Entry->FileHashAnsi = PhConvertUtf16ToMultiByte(Entry->FileHash->Buffer); entry = CreateJsonObject(); JsonAddObject(entry, "autostart_location", ""); JsonAddObject(entry, "autostart_entry", ""); JsonAddObject(entry, "hash", Entry->FileHashAnsi->Buffer); JsonAddObject(entry, "image_path", Entry->FileNameAnsi->Buffer); JsonAddObject(entry, "creation_datetime", Entry->CreationTime ? Entry->CreationTime->Buffer : ""); JsonArrayAddObject(JsonArray, entry); } NtClose(fileHandle); } }
bool Application::Init(int w, int h) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { return EmitSDLError("error initialize SDL"); return false; } #ifdef __APPLE__ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); #else SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); #endif SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); window_ = SDL_CreateWindow(nullptr, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, w, h, SDL_WINDOW_OPENGL); gl_context_ = SDL_GL_CreateContext(window_); if (gl_context_ == nullptr) { return EmitSDLError("error creating GL context"); } // Enable vsync SDL_GL_SetSwapInterval(1); if (TTF_Init() != 0) { return EmitSDLError("error initialize font system"); } std::string resource_folder_name = std::string(kResourceFolderName) + "/"; std::string font_file_name = resource_folder_name + kFontFileName; font_ = TTF_OpenFont(font_file_name.c_str(), 14); if (font_ == nullptr) { std::string message; message += "error read font "; message += kFontFileName; message += "at size " + std::to_string(14); return EmitSDLError(message.c_str()); } std::string demo_file_name = resource_folder_name + kDemoFileName; world_ = ParseWorld((CreateJsonObject(demo_file_name.c_str()))); world_->Start(World::EngineType::kLiquidFun); // We have two camera setup: the first one for viewing the board and the // second one for background. The second camera does not move. cameras_.resize(2); cameras_[0] = make_unique<Camera>(Vector3f(0, -50, 650), Vector3f(0, 50, 0), Vector3f(0, 1, 0), M_PI / 2.0, 1.0, 10.0, 500000.0); cameras_[1] = make_unique<Camera>(Vector3f(0, 0, 800), Vector3f(0, 0, 0), Vector3f(0, 1, 0), M_PI / 2.0, 1.0, 10.0, 500000.0); poly_drawer_ = make_unique<NodeGroupDrawer<NodeBuldgedDrawer>>( LoadMesh3DGLProgram(), cameras_[0].get(), Vector2f(w, h)); path_drawer_ = make_unique<NodeGroupDrawer<NodePathDrawer>>( LoadSimpleGLProgram(), cameras_[0].get(), Vector2f(w, h)); particle_drawer_ = make_unique<NodeGroupDrawer<SphereDrawer>>( LoadSphereGLProgram(), cameras_[0].get(), Vector2f(w, h)); // Add Node to each group drawer. for (size_t i = 0; i < world_->GetNumNodes(); ++i) { auto& collision_shapes = world_->GetNodeByIndex(i)->collision_shapes; if (collision_shapes.size() == 1 && collision_shapes[0]->shape_type == Shape2DType::kDisk) { particle_drawer_->AddNode(world_->GetNodeByIndex(i)); } else { poly_drawer_->AddNode(world_->GetNodeByIndex(i)); } path_drawer_->AddNode(world_->GetNodeByIndex(i)); } text_drawer_ = make_unique<TextDrawer>(font_); // Use the fixed camera for background drawing. canvas_drawer_ = make_unique<CanvasDrawer>(LoadBackgroundGLProgram(), cameras_[1].get(), Vector2f(w, h)); return true; }