# needs Test::CGI::External;
# Minimal test example to check if fileupload
#  via POST and content-type "multipart/form-data"
#  works as expected
#  2021 by Andreas Romeyke <art1@andreas-romeyke.de>
#  you need to compile 'test_file_upload_post_cgicc.cpp' to a.out
#  via: 'g++ test_file_upload_post_cgicc.cpp -lcgicc'
#
#  ignore warnings, relevant is, this script triggers the error and uses
#  correct output  and calls a,out
#
#  You could also add a simple shell script, which prints env (via 'set') and
#  STDIN to a file to compare.
#
# compare the length with output of a.out in debug.* files
use strict;
use warnings;
use utf8;
use feature qw(say);
use Test::More;
use Path::Tiny;
use CGI::Test;
use CGI::Test::Input::Multipart;

my $tester = CGI::Test->new (
    -base_url => "http://localhost/cgi-bin",
    -cgi_dir => "./"
);

path("test.pdf")->spew_raw("test"); # the 'uploaded' file has 4 chars!

# tests
    ###
    note "POST METHOD";
    my $input = CGI::Test::Input::Multipart->new();
    $input->add_file_now("pdffile", "test.pdf");
    $input->data; $input->length;
    use Data::Printer;
    say "input->data:";
    p( $input->data);
    say "input->mimetype:";
    p( $input->mime_type);
    say "input->length";
    p( $input->length);
    my $tc = $tester->POST("http://localhost/cgi-bin/a.out", $input);

done_testing ();
