/* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
group "doc.paged";
require init;
require PAGED_MEDIA_SUPPORT;

language C++;

include "modules/dochand/win.h";
include "modules/doc/frm_doc.h";
include "modules/doc/pagedescription.h";

global
{
	OpWindowCommander::FullScreenState saved_fullscreen_state;
}

html
{
	"<html></html>"
}

test("paged - setup")
{
	verify(state.doc);
	Window* win = state.doc->GetWindow();
	verify(win);
	saved_fullscreen_state = win->GetFullScreenState();
	verify(win->SetFullScreenState(OpWindowCommander::FULLSCREEN_PROJECTION) == OpStatus::OK); // To trigger projection
}

html
{
	//! <html><head>
	//! <style>
	//! @media projection
	//! {
	//!    div.break  { page-break-after: always }
	//! }
	//! </style>
	//! </head>
	//! <body>
	//! <div class="break">Page 1</div>
	//! <div class="break">Page 2</div>
	//! <div>Page 3</div>
	//! </body></html>
}

test("paged.countpages")
{
	verify(state.doc);
	verify(state.doc->CountPages() ==  3);
}

test("paged.advance")
disabled; // Not written yet. Fails quite early.
{
	verify(state.doc);
	PageDescription* current_page = state.doc->GetCurrentPage();
	verify(current_page);
	verify(current_page->GetNumber() == 1);
	PageDescription* first_page = state.doc->GetPage(1);
	verify(first_page);
	verify(current_page == first_page);

	PageDescription* advanced_page = state.doc->AdvancePage(first_page->GetSheetHeight());
	verify(advanced_page);
	verify(advanced_page != first_page);
	verify(advanced_page->GetNumber() == 2);

	PageDescription* second_page = state.doc->GetPage(1);
	verify(second_page);
	verify(advanced_page == second_page);
}

test("paged.rewind")
disabled; // Not written yet. Fails quite early.
{
	verify(state.doc);
	PageDescription* current_page = state.doc->GetCurrentPage();
	verify(current_page);
	verify(current_page->GetNumber() == 2);
	PageDescription* second_page = state.doc->GetPage(1);
	verify(second_page);
	verify(current_page == second_page);

	state.doc->RewindPage(0);
	PageDescription* rewinded_page = state.doc->GetCurrentPage();
	verify(rewinded_page);
	verify(rewinded_page != second_page);
	verify(rewinded_page->GetNumber() == 1);

	PageDescription* first_page = state.doc->GetPage(1);
	verify(first_page);
	verify(rewinded_page == first_page);
}

test("paged - cleanup")
require success "paged - setup";
{
	verify(state.doc);
	Window* win = state.doc->GetWindow();
	verify(win);
	verify(win->SetFullScreenState(saved_fullscreen_state) == OpStatus::OK);
}
