Here are the completed sentences with the verbs in the correct form of the 'past perfect continuous':
1. Sophie **had been painting** the walls all day before she finished them.
2. **Had you been waiting** long when the boss announced that he couldn't see you?
3. Tom **had been looking** for a job for six months when he found one.
4. We **had been watching** TV for half an hour when the doorbell rang.
5. They **had been sunbathing** for an hour when it started to rain.
6. Stan **had been working** as a postman for forty years when he retired.
7. I **had been living** in France for ten years when I met my husband.