github.com/pdfcpu/pdfcpu@v0.11.1/pkg/cli/test/pageMode_test.go (about)

     1  /*
     2  Copyright 2023 The pdfcpu Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8  	http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package test
    18  
    19  import (
    20  	"path/filepath"
    21  	"strings"
    22  	"testing"
    23  
    24  	"github.com/pdfcpu/pdfcpu/pkg/cli"
    25  )
    26  
    27  func TestPageMode(t *testing.T) {
    28  	msg := "testPageMode"
    29  
    30  	pageMode := "UseOutlines"
    31  
    32  	inFile := filepath.Join(inDir, "test.pdf")
    33  	outFile := filepath.Join(outDir, "test.pdf")
    34  
    35  	cmd := cli.ListPageModeCommand(inFile, conf)
    36  	ss, err := cli.Process(cmd)
    37  	if err != nil {
    38  		t.Fatalf("%s %s: list pageMode: %v\n", msg, inFile, err)
    39  	}
    40  	if len(ss) > 0 && !strings.HasPrefix(ss[0], "No page mode") {
    41  		t.Fatalf("%s %s: list pageMode, unexpected: %s\n", msg, inFile, ss[0])
    42  	}
    43  
    44  	cmd = cli.SetPageModeCommand(inFile, outFile, pageMode, nil)
    45  	if _, err = cli.Process(cmd); err != nil {
    46  		t.Fatalf("%s %s: set pageMode: %v\n", msg, outFile, err)
    47  	}
    48  
    49  	cmd = cli.ListPageModeCommand(outFile, conf)
    50  	ss, err = cli.Process(cmd)
    51  	if err != nil {
    52  		t.Fatalf("%s %s: list pageMode: %v\n", msg, outFile, err)
    53  	}
    54  	if len(ss) == 0 {
    55  		t.Fatalf("%s %s: list pageMode, missing pageMode\n", msg, outFile)
    56  	}
    57  	if ss[0] != pageMode {
    58  		t.Fatalf("%s %s: list pageMode, want:%s, got:%s\n", msg, outFile, pageMode, ss[0])
    59  	}
    60  
    61  	cmd = cli.ResetPageModeCommand(outFile, "", nil)
    62  	if _, err = cli.Process(cmd); err != nil {
    63  		t.Fatalf("%s %s: reset pageMode: %v\n", msg, outFile, err)
    64  	}
    65  
    66  	cmd = cli.ListPageModeCommand(outFile, conf)
    67  	ss, err = cli.Process(cmd)
    68  	if err != nil {
    69  		t.Fatalf("%s %s: list pageMode: %v\n", msg, outFile, err)
    70  	}
    71  	if len(ss) > 0 && !strings.HasPrefix(ss[0], "No page mode") {
    72  		t.Fatalf("%s %s: list pageMode, unexpected: %s\n", msg, outFile, ss[0])
    73  	}
    74  }