Alexander Afanasyev | ec1d4a7 | 2012-03-05 11:06:54 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn> |
| 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | #include "../model/sync-digest.h" |
| 24 | #include <iostream> |
| 25 | |
| 26 | using namespace Sync; |
| 27 | using namespace std; |
| 28 | |
| 29 | int |
| 30 | main (int argc, char **argv) |
| 31 | { |
| 32 | Digest test; |
| 33 | test << "1"; |
| 34 | |
| 35 | try |
| 36 | { |
| 37 | cout << "Trying to print without explicit getHash() call: "; |
| 38 | cout << test; |
| 39 | cout << "Failed (should be asserted)\n"; |
| 40 | } |
| 41 | catch (...) |
| 42 | { |
| 43 | cout << "OK (exception)\n"; |
| 44 | } |
| 45 | |
| 46 | // without explicit finalizing, Digest will not be complete and printing out will cause assert |
| 47 | test.getHash (); |
| 48 | |
| 49 | try |
| 50 | { |
| 51 | cout << "Hash for '1' is " << test << std::endl; |
| 52 | } |
| 53 | catch (...) |
| 54 | { |
| 55 | cout << "Hash calculation failed\n"; |
| 56 | } |
| 57 | |
| 58 | try |
| 59 | { |
| 60 | cout << "Trying to add data to hash after finalizing: "; |
| 61 | test << "2"; // should cause an assert |
| 62 | cout << "Failed (should be asserted)\n"; |
| 63 | } |
| 64 | catch (...) |
| 65 | { |
| 66 | cout << "OK (exception)\n"; |
| 67 | } |
| 68 | return 0; |
| 69 | } |