#!/usr/bin/env python
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 2; coding: utf-8 -*-
#
# This file is part of Déjà Dup.
# © 2008,2009 Michael Terry <mike@mterry.name>
#
# Déjà Dup is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Déjà Dup is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Déjà Dup.  If not, see <http://www.gnu.org/licenses/>.

# Test whether we correctly switch to full backup mode vs incremental

import sys
sys.path.insert(0, sys.path[0]+'/..')
import base
import ldtp

max_allowed = 24 * 7
scale = 12

def max_inc():
  base.setup('file', encrypt=False, sources=['data/simple'])
  base.backup_simple()
  # Change date to maximum allowed incremental, confirm next is incremental
  base.last_date_change('%d days ago' % (max_allowed))
  base.start_deja_dup()
  base.backup_simple()
  rv = base.last_type() == 'inc'
  return rv

def max_full():
  base.setup('file', encrypt=False, sources=['data/simple'])
  base.backup_simple()
  # Change date to maximum allowed incremental+1, confirm next is full
  base.last_date_change('%d days ago' % (max_allowed+1))
  base.start_deja_dup()
  base.backup_simple()
  rv = base.last_type() == 'full'
  return rv

def half_inc():
  base.setup('file', encrypt=False, sources=['data/simple'])
  base.set_gconf_value("delete-after", '20', 'int')
  base.backup_simple()
  # Change date to maximum allowed incremental, confirm next is inc
  base.last_date_change('%d days ago' % (10))
  base.start_deja_dup()
  base.backup_simple()
  rv = base.last_type() == 'inc'
  return rv

def half_full():
  base.setup('file', encrypt=False, sources=['data/simple'])
  base.set_gconf_value("delete-after", '20', 'int')
  base.backup_simple()
  # Change date to maximum allowed incremental+1, confirm next is full
  base.last_date_change('%d days ago' % (11))
  base.start_deja_dup()
  base.backup_simple()
  rv = base.last_type() == 'full'
  return rv

def period_inc():
  base.setup('file', encrypt=False, sources=['data/simple'])
  base.set_gconf_value("periodic", 'true', 'bool')
  base.set_gconf_value("periodic-period", '7', 'int')
  base.backup_simple()
  # Change date to maximum allowed incremental, confirm next is inc
  base.last_date_change('%d days ago' % (7*scale))
  base.start_deja_dup()
  base.backup_simple()
  rv = base.last_type() == 'inc'
  return rv

def period_full():
  base.setup('file', encrypt=False, sources=['data/simple'])
  base.set_gconf_value("periodic", 'true', 'bool')
  base.set_gconf_value("periodic-period", '7', 'int')
  base.backup_simple()
  # Change date to maximum allowed incremental+1, confirm next is full
  base.last_date_change('%d days ago' % ((7*scale)+1))
  base.start_deja_dup()
  base.backup_simple()
  rv = base.last_type() == 'full'
  return rv

base.run(max_inc)
base.run(max_full)
base.run(half_inc)
base.run(half_full) # optimism!
base.run(period_inc)
base.run(period_full)
