From cda11dbd6f082c08a4cd6f6cc780d6511d9b8b1b Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sat, 21 Sep 2019 18:20:05 +0800 Subject: [PATCH] [test-account-summary] initial commit --- .../standard-reports/test/CMakeLists.txt | 1 + .../test/test-account-summary.scm | 82 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 gnucash/report/standard-reports/test/test-account-summary.scm diff --git a/gnucash/report/standard-reports/test/CMakeLists.txt b/gnucash/report/standard-reports/test/CMakeLists.txt index 4b5994550c..97b09f68a0 100644 --- a/gnucash/report/standard-reports/test/CMakeLists.txt +++ b/gnucash/report/standard-reports/test/CMakeLists.txt @@ -9,6 +9,7 @@ set(scm_test_with_srfi64_SOURCES test-cashflow-barchart.scm test-charts.scm test-transaction.scm + test-account-summary.scm test-balsheet-pnl.scm test-income-gst.scm test-budget.scm diff --git a/gnucash/report/standard-reports/test/test-account-summary.scm b/gnucash/report/standard-reports/test/test-account-summary.scm new file mode 100644 index 0000000000..e09e79e609 --- /dev/null +++ b/gnucash/report/standard-reports/test/test-account-summary.scm @@ -0,0 +1,82 @@ +(use-modules (gnucash gnc-module)) +(gnc:module-begin-syntax (gnc:module-load "gnucash/app-utils" 0)) +(use-modules (gnucash engine test test-extras)) +(use-modules (gnucash report standard-reports account-summary)) +(use-modules (gnucash report standard-reports sx-summary)) +(use-modules (gnucash report stylesheets)) +(use-modules (gnucash report report-system)) +(use-modules (gnucash report report-system test test-extras)) +(use-modules (srfi srfi-64)) +(use-modules (gnucash engine test srfi64-extras)) +(use-modules (sxml simple)) +(use-modules (sxml xpath)) + +(define accsum-uuid "3298541c236b494998b236dfad6ad752") +(define fsts-uuid "47f45d7d6d57b68518481c1fc8d4e4ba") + +;; Explicitly set locale to make the report output predictable +(setlocale LC_ALL "C") + +(define (run-test) + (test-runner-factory gnc:test-runner) + (test-setup) + (test-begin "accsum-and-fsts") + (accsum-tests) + (test-end "accsum-and-fsts")) + +(define (test-setup) + (define (mnemonic->commodity sym) + (gnc-commodity-table-lookup + (gnc-commodity-table-get-table (gnc-get-current-book)) + (gnc-commodity-get-namespace (gnc-default-report-currency)) + sym)) + (define GBP (mnemonic->commodity "GBP")) + (gnc-commodity-set-user-symbol GBP "#")) + +(define (options->sxml uuid options test-title) + (gnc:options->sxml uuid options "test-accsum" test-title)) + +(define (set-option! options section name value) + (let ((option (gnc:lookup-option options section name))) + (if option + (gnc:option-set-value option value) + (test-assert (format #f "wrong-option ~a ~a" section name) #f)))) + +(define (accsum-tests) + (let* ((account-alist (create-test-data)) + (income (assoc-ref "Income" account-alist))) + + (define (default-testing-options uuid) + (gnc:make-report-options uuid)) + + + (test-begin "account-summary") + (let* ((options (default-testing-options accsum-uuid)) + (sxml (options->sxml accsum-uuid options "accsum"))) + (test-equal "accsum col 1" + '("Code" "#608.00" "-#612.00" "#608.00" "-#612.00" "#608.00" "-#612.00") + (sxml->table-row-col sxml 1 #f 1)) + (test-equal "accsum col 2" + '("Account title" "Root" "Asset" "Bank" "GBP Bank" "Wallet" + "Liabilities" "Income" "Income-GBP" "Expenses" "Equity") + (sxml->table-row-col sxml 1 #f 2)) + (test-equal "accsum col 3" + '("$2,186.00" "#608.00" "$912.00" "$912.00" "$20.00" + "-$918.00" "$912.00" "-$918.00" "$912.00" "-$918.00") + (sxml->table-row-col sxml 1 #f 3))) + (test-end "account-summary") + + (test-begin "fsts") + (let* ((options (default-testing-options fsts-uuid)) + (sxml (options->sxml fsts-uuid options "fsts"))) + (test-equal "fsts col 1" + '("Code") + (sxml->table-row-col sxml 1 #f 1)) + (test-equal "fsts col 2" + '("Account title" "Root" "Asset" "Bank" "GBP Bank" "Wallet" + "Liabilities" "Income" "Income-GBP" "Expenses" "Equity") + (sxml->table-row-col sxml 1 #f 2)) + (test-equal "fsts col 3" + '("$0.00" "$0.00" "$0.00") + (sxml->table-row-col sxml 1 #f 3))) + (test-end "fsts")))